private DiskState validatePut(Operation op) { DiskState state = processInput(op); DiskState currentState = getState(op); ResourceUtils.validatePut(state, currentState); return state; }
@Override public void handlePatch(Operation patch) { DiskState currentState = getState(patch); Function<Operation, Boolean> customPatchHandler = new Function<Operation, Boolean>() { @Override public Boolean apply(Operation t) { DiskState patchBody = patch.getBody(DiskState.class); boolean hasStateChanged = false; if (patchBody.capacityMBytes != 0 && patchBody.capacityMBytes != currentState.capacityMBytes) { currentState.capacityMBytes = patchBody.capacityMBytes; hasStateChanged = true; } return hasStateChanged; } }; ResourceUtils.handlePatch(patch, currentState, getStateDescription(), DiskState.class, customPatchHandler); }
@Override public void handlePut(Operation put) { try { DiskState returnState = processInput(put); setState(put, returnState); put.complete(); } catch (Throwable t) { put.fail(t); } }
@Override public void handlePut(Operation put) { if (PhotonModelUtils.isFromMigration(put)) { super.handlePut(put); return; } DiskState returnState = validatePut(put); ResourceUtils.populateTags(this, returnState) .thenAccept(__ -> { ResourceUtils.updateNoEndpointFlag(returnState, getState(put), DiskState.class); setState(put, returnState); }) .whenCompleteNotify(put); }
patch.fail(new IllegalArgumentException("tagLink cannot have null elements. " + "diskLink = " + patchState.documentSelfLink)); logWarning("Failing attempt to PATCH null tagLinks element to DiskState " + "[Referrer:%s], [DiskLink:%s]", patch.getReferer(), patchState.documentSelfLink); DiskState currentState = getState(patch); Function<Operation, Boolean> customPatchHandler = new Function<Operation, Boolean>() { @Override ResourceUtils.handlePatch(this, patch, currentState, getStateDescription(), DiskState.class, customPatchHandler);
@Override public void handleGet(Operation get) { DiskState currentState = getState(get); boolean doExpand = get.getUri().getQuery() != null && UriUtils.hasODataExpandParamValue(get.getUri()); dsExpanded.storageDescription = o.getBody(StorageDescription.class); } else { logFine("Could not fetch storage description %s due to %s", currentState.storageDescriptionLink, e.getMessage());
private DiskState processInput(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } DiskState state = op.getBody(DiskState.class); validateState(state); return state; }
@Override public void handleStart(Operation start) { try { processInput(start); start.complete(); } catch (Throwable t) { start.fail(t); } }
private void validateState(DiskState state) { Utils.validateState(getStateDescription(), state); if (state.name == null) { throw new IllegalArgumentException("name is required."); } if (state.status == null) { state.status = DiskStatus.DETACHED; } if (state.bootConfig != null) { for (DiskState.BootConfig.FileEntry entry : state.bootConfig.files) { if (entry.path == null || entry.path.length() == 0) { throw new IllegalArgumentException( "FileEntry.path is required"); } } } }
@Override public void handleDelete(Operation delete) { logInfo("Deleting Disk, Path: %s, Operation ID: %d, Referrer: %s", delete.getUri().getPath(), delete.getId(), delete.getRefererAsString()); super.handleDelete(delete); }
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()); } }
@Override public void handleGet(Operation get) { DiskState currentState = getState(get); boolean doExpand = get.getUri().getQuery() != null && UriUtils.hasODataExpandParamValue(get.getUri()); dsExpanded.storageDescription = o.getBody(StorageDescription.class); } else { logFine("Could not fetch storage description %s due to %s", currentState.storageDescriptionLink, e.getMessage());
private DiskState processInput(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } DiskState state = op.getBody(DiskState.class); validateState(state); return state; }
@Override public void handleCreate(Operation start) { if (PhotonModelUtils.isFromMigration(start)) { start.complete(); return; } DiskState state = processInput(start); state.documentCreationTimeMicros = Utils.getNowMicrosUtc(); ResourceUtils.populateTags(this, state) .thenAccept(__ -> ResourceUtils.initNoEndpointFlag(state, DiskState.class)) .whenCompleteNotify(start); }
private void validateState(DiskState state) { Utils.validateState(getStateDescription(), state); if (state.name == null) { throw new IllegalArgumentException("name is required."); } if (state.status == null) { state.status = DiskStatus.DETACHED; } if (state.bootConfig != null) { for (DiskState.BootConfig.FileEntry entry : state.bootConfig.files) { if (entry.path == null || entry.path.length() == 0) { throw new IllegalArgumentException( "FileEntry.path is required"); } } } }