|
|
|
|
@ -108,8 +108,8 @@ final class CloudInstanceResourceRelease
|
|
|
|
|
'id',
|
|
|
|
|
$reservationId
|
|
|
|
|
)->lockForUpdate()->first();
|
|
|
|
|
self::assertOrderReservation(
|
|
|
|
|
$order,
|
|
|
|
|
self::assertOrderOwned(
|
|
|
|
|
$instance,
|
|
|
|
|
$reservation,
|
|
|
|
|
['committed']
|
|
|
|
|
);
|
|
|
|
|
@ -176,52 +176,22 @@ final class CloudInstanceResourceRelease
|
|
|
|
|
)->first();
|
|
|
|
|
if (!$order instanceof CloudOrder
|
|
|
|
|
|| (int) ($instance->order_id ?? 0) !== (int) $order->id
|
|
|
|
|
|| (int) ($instance->reservation_id ?? 0)
|
|
|
|
|
!== (int) $reservation->id
|
|
|
|
|
|| (int) ($instance->offer_id ?? 0) !== (int) $order->offer_id
|
|
|
|
|
|| (int) $instance->user_id !== (int) $order->user_id
|
|
|
|
|
|| (int) $instance->host_id !== (int) $order->host_id
|
|
|
|
|
|| (int) ($instance->resource_pool_id ?? 0)
|
|
|
|
|
!== (int) $order->resource_pool_id
|
|
|
|
|
|| (int) ($reservation->instance_id ?? 0)
|
|
|
|
|
!== (int) $instance->id) {
|
|
|
|
|
|| (int) ($order->reservation_id ?? 0)
|
|
|
|
|
!== (int) $reservation->id) {
|
|
|
|
|
throw new CloudError('实例的订单资源账本不一致', 409);
|
|
|
|
|
}
|
|
|
|
|
self::assertOrderReservation($order, $reservation, $allowedStates);
|
|
|
|
|
CloudPlacementService::assertCurrentOrderPlacement(
|
|
|
|
|
$instance,
|
|
|
|
|
$reservation,
|
|
|
|
|
$allowedStates
|
|
|
|
|
);
|
|
|
|
|
return $order;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function assertOrderReservation(
|
|
|
|
|
CloudOrder $order,
|
|
|
|
|
?CloudResourceReservation $reservation,
|
|
|
|
|
array $allowedStates
|
|
|
|
|
): void {
|
|
|
|
|
if (!$reservation instanceof CloudResourceReservation
|
|
|
|
|
|| (int) ($reservation->order_id ?? 0) !== (int) $order->id
|
|
|
|
|
|| (int) ($reservation->user_id ?? 0) !== (int) $order->user_id
|
|
|
|
|
|| (int) ($reservation->offer_id ?? 0) !== (int) $order->offer_id
|
|
|
|
|
|| (int) ($reservation->resource_pool_id ?? 0)
|
|
|
|
|
!== (int) $order->resource_pool_id
|
|
|
|
|
|| (int) ($reservation->host_id ?? 0)
|
|
|
|
|
!== (int) $order->host_id
|
|
|
|
|
|| (int) ($order->reservation_id ?? 0)
|
|
|
|
|
!== (int) ($reservation->id ?? 0)
|
|
|
|
|
|| (int) ($reservation->backup_restore_id ?? 0) !== 0
|
|
|
|
|
|| (string) ($reservation->backup_restore_attempt_key ?? '') !== ''
|
|
|
|
|
|| (int) ($reservation->migration_source_debt_id ?? 0) !== 0
|
|
|
|
|
|| preg_match(
|
|
|
|
|
'/^[a-f0-9]{32}$/D',
|
|
|
|
|
(string) ($reservation->operation_id ?? '')
|
|
|
|
|
) !== 1
|
|
|
|
|
|| !in_array(
|
|
|
|
|
(string) ($reservation->state ?? ''),
|
|
|
|
|
$allowedStates,
|
|
|
|
|
true
|
|
|
|
|
)) {
|
|
|
|
|
throw new CloudError('开通订单的资源预留账本不一致', 409);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function releaseReason(string $reason): string
|
|
|
|
|
{
|
|
|
|
|
$reason = strtolower(trim($reason));
|
|
|
|
|
|