Search in sources :

Example 1 with BaseAdapterStage

use of com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage in project photon-model by vmware.

the class AWSInstanceService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    AWSInstanceContext ctx = new AWSInstanceContext(this, op.getBody(ComputeInstanceRequest.class));
    try {
        final BaseAdapterStage startingStage;
        final AWSInstanceStage nextStage;
        switch(ctx.computeRequest.requestType) {
            case VALIDATE_CREDENTIALS:
                ctx.operation = op;
                startingStage = BaseAdapterStage.PARENTAUTH;
                nextStage = AWSInstanceStage.CLIENT;
                break;
            default:
                op.complete();
                if (ctx.computeRequest.isMockRequest && ctx.computeRequest.requestType == InstanceRequestType.CREATE) {
                    ctx.taskManager.finishTask();
                    return;
                }
                startingStage = BaseAdapterStage.VMDESC;
                nextStage = AWSInstanceStage.PROVISIONTASK;
                break;
        }
        // Populate BaseAdapterContext and then continue with this state machine
        ctx.populateBaseContext(startingStage).whenComplete(thenAllocation(ctx, nextStage));
    } catch (Throwable t) {
        finishExceptionally(ctx, t);
    }
}
Also used : BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)

Example 2 with BaseAdapterStage

use of com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage in project photon-model by vmware.

the class AzureInstanceService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    AzureInstanceContext ctx = new AzureInstanceContext(this, op.getBody(ComputeInstanceRequest.class));
    final BaseAdapterStage startingStage;
    switch(ctx.computeRequest.requestType) {
        case VALIDATE_CREDENTIALS:
            ctx.operation = op;
            startingStage = BaseAdapterStage.PARENTAUTH;
            break;
        default:
            op.complete();
            if (ctx.computeRequest.isMockRequest && ctx.computeRequest.requestType == InstanceRequestType.CREATE) {
                handleAllocation(ctx, AzureInstanceStage.FINISHED);
                return;
            }
            startingStage = BaseAdapterStage.VMDESC;
            break;
    }
    // Populate BaseAdapterContext and then continue with this state machine
    ctx.populateBaseContext(startingStage).whenComplete(thenAllocation(ctx, AzureInstanceStage.CLIENT));
}
Also used : BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)

Aggregations

ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)2 BaseAdapterStage (com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage)2