当前位置: 首页>>代码示例>>Java>>正文


Java Operation.setStatusCode方法代码示例

本文整理汇总了Java中com.vmware.xenon.common.Operation.setStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java Operation.setStatusCode方法的具体用法?Java Operation.setStatusCode怎么用?Java Operation.setStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vmware.xenon.common.Operation的用法示例。


在下文中一共展示了Operation.setStatusCode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation patch) {
    try {
        ScheduledTaskState patchBody = getBody(patch);
        Utils.validateState(getStateDescription(), patchBody);
        ScheduledTaskState currentState = getState(patch);
        boolean hasStateChanged = Utils.mergeWithState(getStateDescription(),
                currentState, patchBody);
        if (!hasStateChanged) {
            patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
        } else {
            patch.setBody(currentState);
        }
        patch.complete();
    } catch (Throwable e) {
        patch.fail(e);
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:19,代码来源:ScheduledTaskService.java

示例2: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    ComputePowerRequest request = op.getBody(ComputePowerRequest.class);

    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();

    ProvisionContext.populateContextThen(this, createInitialContext(request), ctx -> {
        if (request.isMockRequest) {
            patchComputeAndCompleteRequest(request, ctx);
            return;
        }

        handlePowerRequest(ctx, request);
    });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:VSphereAdapterPowerService.java

示例3: handleIdempotentPut

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
public static void handleIdempotentPut(StatefulService s, Operation put) {

        if (put.hasPragmaDirective(Operation.PRAGMA_DIRECTIVE_POST_TO_PUT)) {
            // converted PUT due to IDEMPOTENT_POST option
            s.logFine(() -> String.format("Task %s has already started. Ignoring converted PUT.",
                    put.getUri()));
            put.setBody(s.getState(put));
            put.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED);
            put.setStatusCode(Operation.STATUS_CODE_OK);
            put.complete();
            return;
        }

        // normal PUT is not supported
        put.fail(Operation.STATUS_CODE_BAD_METHOD);
    }
 
开发者ID:vmware,项目名称:photon-model,代码行数:17,代码来源:PhotonModelUtils.java

示例4: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation patch) {
    ResourceOperationSpec currentState = getState(patch);
    ResourceOperationSpec body = patch.getBody(ResourceOperationSpec.class);

    validate(body, patch.getRefererAsString());
    boolean merged = Utils.mergeWithState(getStateDescription(), currentState, body);

    if (merged) {
        logFine("%s updated.", currentState);
    } else {
        patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
    }
    patch.complete();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:16,代码来源:ResourceOperationSpecService.java

示例5: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }

    ResourceOperationRequest request = op.getBody(ResourceOperationRequest.class);
    try {
        validateInputRequest(request);
    } catch (Exception e) {
        op.fail(e);
        return;
    }
    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();

    TaskManager taskManager = new TaskManager(this, request.taskReference,
            request.resourceLink());
    logInfo("Handle operation %s for compute %s.", request.operation, request.resourceLink());

    VSphereVMDiskContext
            .populateVMDiskContextThen(this, createInitialContext(taskManager, request),
                    ctx -> {
                        if (request.operation.equals(ResourceOperation.ATTACH_DISK.operation)) {
                            handleAttachDisk(ctx);
                        } else if (request.operation.equals(ResourceOperation.DETACH_DISK.operation)) {
                            handleDetachDisk(ctx);
                        } else {
                            IllegalArgumentException exception = new IllegalArgumentException(
                                    String.format("Unknown Operation %s for a disk",
                                            request.operation));
                            ctx.fail(exception);
                        }
                    });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:37,代码来源:VSphereComputeDiskManagementService.java

示例6: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }

    ComputeEnumerateResourceRequest request = op.getBody(ComputeEnumerateResourceRequest.class);

    validate(request);

    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();

    TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());

    if (request.isMockRequest) {
        // just finish the mock request
        mgr.patchTask(TaskStage.FINISHED);
        return;
    }

    URI parentUri = ComputeStateWithDescription.buildUri(PhotonModelUriUtils.createInventoryUri(getHost(),
            request.resourceReference));

    Operation.createGet(parentUri)
            .setCompletion(o -> {
                thenWithParentState(request, o.getBody(ComputeStateWithDescription.class), mgr);
            }, mgr)
            .sendWith(this);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:32,代码来源:VSphereAdapterResourceEnumerationService.java

示例7: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }

    DiskInstanceRequest request = op.getBody(DiskInstanceRequest.class);
    try {
        validateInputRequest(request);
    } catch (Exception e) {
        op.fail(e);
        return;
    }

    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();

    TaskManager taskManager = new TaskManager(this, request.taskReference,
            request.resourceLink());

    DiskContext.populateContextThen(this, createInitialContext(taskManager, request), ctx -> {
        switch (request.requestType) {
        case CREATE:
            handleCreateDisk(ctx);
            break;
        case DELETE:
            handleDeleteDisk(ctx);
            break;
        default:
            Throwable error = new IllegalStateException(
                    "Unsupported requestType " + request.requestType);
            ctx.fail(error);
        }
    });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:37,代码来源:VSphereDiskService.java

示例8: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }

    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();

    ComputeInstanceRequest request = op.getBody(ComputeInstanceRequest.class);

    TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());

    if (request.isMockRequest) {
        handleMockRequest(mgr);
        return;
    }

    ProvisionContext.populateContextThen(this, createInitialContext(request), ctx -> {
        switch (request.requestType) {
        case CREATE:
            handleCreateInstance(ctx);
            break;
        case DELETE:
            handleDeleteInstance(ctx);
            break;
        default:
            Throwable error = new IllegalStateException(
                    "Unsupported requestType " + request.requestType);
            ctx.fail(error);
        }
    });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:35,代码来源:VSphereAdapterInstanceService.java

示例9: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }

    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();

    ImageEnumerateRequest request = op.getBody(ImageEnumerateRequest.class);

    validate(request);

    TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());

    if (request.isMockRequest) {
        // just finish the mock request
        mgr.patchTask(TaskStage.FINISHED);
        return;
    }

    Operation.createGet(PhotonModelUriUtils.createInventoryUri(getHost(), request.resourceReference))
            .setCompletion(
                    o -> thenWithEndpointState(request, o.getBody(EndpointState.class), mgr),
                    mgr)
            .sendWith(this);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:29,代码来源:VSphereAdapterImageEnumerationService.java

示例10: handlePatch

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
@Override
public void handlePatch(Operation patch) {
    // Only allow the external field and the deleted field to be changed
    TagState patchState = patch.getBody(TagState.class);
    TagState currentState = getState(patch);

    if (!ServiceDocument.equals(getStateDescription(), currentState, patchState)) {
        patch.fail(new UnsupportedOperationException("Tags may not be modified"));
        return;
    }

    boolean modified = false;
    if (patchState.external != null) {
        if (currentState.external == null || (Boolean.TRUE.equals(currentState.external)
                && Boolean.FALSE.equals(patchState.external))) {
            currentState.external = patchState.external;
            modified = true;
        }
    }

    // update the deleted property accordingly
    if (patchState.deleted != null) {
        currentState.deleted = patchState.deleted;
        modified = true;
    }

    if (!modified) {
        patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
    }

    patch.setBody(currentState);
    patch.complete();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:34,代码来源:TagService.java

示例11: handleValidationException

import com.vmware.xenon.common.Operation; //导入方法依赖的package包/类
private static void handleValidationException(Operation op, Throwable e) {
    Throwable ex = e;
    if (!(e instanceof IllegalArgumentException)
            && !(e instanceof LocalizableValidationException)) {
        ex = new IllegalArgumentException(e.getMessage());
    }
    op.setStatusCode(Operation.STATUS_CODE_BAD_REQUEST);
    // with body = null fail(ex) will populate it with the proper ServiceErrorResponse content
    op.setBody(null);
    op.fail(ex);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:12,代码来源:SslTrustCertificateService.java


注:本文中的com.vmware.xenon.common.Operation.setStatusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。