private ComputeState validatePut(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } ComputeState state = op.getBody(ComputeState.class); ComputeState currentState = getState(op); if (state.type != null && currentState.type != null && state.type != currentState.type) { throw new IllegalArgumentException("Compute type can not be changed"); } if (state.environmentName != null && currentState.environmentName != null && !state.environmentName.equals(currentState.environmentName)) { throw new IllegalArgumentException("Environment name can not be changed"); } validateDiskLinks(state, currentState, op); ResourceUtils.validatePut(state, currentState); Utils.validateState(getStateDescription(), state); return state; }
@Override public void handlePut(Operation put) { try { ComputeState returnState = validatePut(put); setState(put, returnState); put.complete(); } catch (Throwable t) { put.fail(t); } }
@Override public void handleCreate(Operation start) { try { validateCreate(start); start.complete(); } catch (Throwable t) { start.fail(t); } }
private void validateDiskLinks(ComputeState state, ComputeState currentState, Operation op) { if (checkDuplicatedDiskLinks(state)) { // There are duplicate diskLinks in the body String duplicateDiskLinksError = String.format( "Referer '%s' is making a call with " + "repeated disk links to ComputeState#id: '%s'.", op.getReferer(), state.id); if (checkDuplicatedDiskLinks(currentState)) { duplicateDiskLinksError += " Current disk links are also not unique."; } logSevere(duplicateDiskLinksError); if (FAIL_ON_NON_UNIQUE_LINKS) { op.fail(new IllegalStateException(duplicateDiskLinksError)); } } }
private ComputeState validatePut(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } ComputeState state = op.getBody(ComputeState.class); ComputeState currentState = getState(op); if (state.type != null && currentState.type != null && state.type != currentState.type) { throw new IllegalArgumentException("Compute type can not be changed"); } if (state.environmentName != null && currentState.environmentName != null && !state.environmentName.equals(currentState.environmentName)) { throw new IllegalArgumentException("Environment name can not be changed"); } Utils.validateState(getStateDescription(), state); return state; }
patch.fail(new IllegalArgumentException("tagLink cannot have null elements. " + "computeLink = " + patchState.documentSelfLink)); logWarning("Failing attempt to PATCH null tagLinks element to ComputeState " + "[Referrer:%s], [ComputeLink:%s]", patch.getReferer(), patchState.documentSelfLink); ComputeState currentState = getState(patch); ResourceUtils.handlePatch(this, patch, currentState, getStateDescription(), ComputeState.class, customPatchHandler);
@Override public void handleGet(Operation get) { ComputeState currentState = getState(get); boolean doExpand = get.getUri().getQuery() != null && UriUtils.hasODataExpandParamValue(get.getUri()); if (!doExpand) { get.setBody(currentState).complete(); return; } // retrieve the description and include in an augmented version of our // state. Operation getDesc = Operation .createGet(this, currentState.descriptionLink) .setCompletion( (o, e) -> { if (e != null) { get.fail(e); return; } ComputeDescription desc = o .getBody(ComputeDescription.class); ComputeStateWithDescription chsWithDesc = ComputeStateWithDescription .create(desc, currentState); get.setBody(chsWithDesc).complete(); }); sendRequest(getDesc); }
private void startServices() { host.startFactory(new ComputeService()); host.startService(new SslTrustCertificateFactoryService()); waitForServices( SslTrustCertificateService.FACTORY_LINK, ComputeService.FACTORY_LINK); }
private ComputeState validateCreate(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } ComputeState state = op.getBody(ComputeState.class); if (state.lifecycleState == null) { state.lifecycleState = LifecycleState.READY; } if (state.powerState == null) { state.powerState = PowerState.UNKNOWN; } Utils.validateState(getStateDescription(), state); return state; }
@Override public void handleDelete(Operation delete) { logInfo("Deleting Compute, Path: %s, Operation ID: %d, Referrer: %s", delete.getUri().getPath(), delete.getId(), delete.getRefererAsString()); super.handleDelete(delete); }
@Override public void handlePatch(Operation patch) { ComputeState currentState = getState(patch); Function<Operation, Boolean> customPatchHandler = t -> { boolean hasStateChanged = false; ResourceUtils.handlePatch(patch, currentState, getStateDescription(), ComputeState.class, customPatchHandler);
@Override public void handleGet(Operation get) { ComputeState currentState = getState(get); boolean doExpand = get.getUri().getQuery() != null && UriUtils.hasODataExpandParamValue(get.getUri()); if (!doExpand) { get.setBody(currentState).complete(); return; } // retrieve the description and include in an augmented version of our // state. Operation getDesc = Operation .createGet(this, currentState.descriptionLink) .setCompletion( (o, e) -> { if (e != null) { get.fail(e); return; } ComputeDescription desc = o .getBody(ComputeDescription.class); ComputeStateWithDescription chsWithDesc = ComputeStateWithDescription .create(desc, currentState); get.setBody(chsWithDesc).complete(); }); sendRequest(getDesc); }
public static void startServices(ServiceHost host) throws Throwable { host.startFactory(new ComputeDescriptionService()); host.startFactory(new ComputeService()); host.startFactory(new ResourcePoolService()); host.startFactory(new ResourceDescriptionService()); host.startFactory(new DiskService()); host.startFactory(new SnapshotService()); host.startFactory(new NetworkInterfaceService()); host.startFactory(new NetworkInterfaceDescriptionService()); host.startFactory(new SubnetService()); host.startFactory(new SubnetRangeService()); host.startFactory(new IPAddressService()); host.startFactory(new ResourceGroupService()); host.startFactory(new NetworkService()); host.startFactory(new FirewallService()); host.startFactory(new SecurityGroupService()); host.startFactory(new StorageDescriptionService()); host.startFactory(new EndpointService()); host.startFactory(new ImageService()); host.startFactory(new InMemoryResourceMetricService()); host.startFactory(TagService.class, TagFactoryService::new); host.startFactory(new LoadBalancerDescriptionService()); host.startFactory(new LoadBalancerService()); host.startFactory(new RouterService()); } }
private ComputeState validateCreate(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } ComputeState state = op.getBody(ComputeState.class); if (state.lifecycleState == null) { state.lifecycleState = LifecycleState.READY; } if (state.powerState == null) { state.powerState = PowerState.UNKNOWN; } Utils.validateState(getStateDescription(), state); return state; }
@Override public void handlePut(Operation put) { if (PhotonModelUtils.isFromMigration(put)) { super.handlePut(put); return; } ComputeState returnState = validatePut(put); ResourceUtils.populateTags(this, returnState) .thenAccept(__ -> setState(put, returnState)) .whenCompleteNotify(put); }
@Override public void handleCreate(Operation start) { if (PhotonModelUtils.isFromMigration(start)) { start.complete(); return; } ComputeState state = validateCreate(start); state.documentCreationTimeMicros = Utils.getNowMicrosUtc(); ResourceUtils.populateTags(this, state) .whenCompleteNotify(start); }