@Override public void handlePut(Operation put) { IPAddressState newState = processInput(put); // Verify valid status changes IPAddressState currentState = getState(put); validateIPAddressStatusTransition(currentState, newState); setState(put, newState); put.complete(); }
@Override public void handlePatch(Operation patch) { if (!patch.hasBody()) { throw (new IllegalArgumentException("body is required")); } IPAddressState currentState = getState(patch); ResourceUtils.handlePatch(patch, currentState, getStateDescription(), IPAddressState.class, op -> { IPAddressState patchState = patch.getBody(IPAddressState.class); boolean hasChanged = false; // Verify valid status changes if (patchState.ipAddressStatus != null && patchState.ipAddressStatus != currentState.ipAddressStatus) { validateIPAddressStatusTransition(currentState, patchState); currentState.ipAddressStatus = patchState.ipAddressStatus; validateIPAddressStatusWithConnectedResource(currentState); hasChanged = true; } return Boolean.valueOf(hasChanged); }); }
/** * Validation upon creation of an IP address object. * - valid IP address * No need to validate that the IP is within the range. * * @param state IpAddressState to validate * @throws IllegalArgumentException for invalid state */ private void validateState(IPAddressState state) { // Verify values based on the document description Utils.validateState(getStateDescription(), state); if (state.ipVersion == null) { state.ipVersion = DEFAULT_IP_VERSION; } if (!SubnetValidator.isValidIPAddress(state.ipAddress, state.ipVersion)) { throw new LocalizableValidationException(String.format("Invalid IP address: %s", state.ipAddress), "ip.address.invalid", state.ipAddress); } validateIPAddressStatusWithConnectedResource(state); logFine("Completed validation of IPAddressState: " + state); }
@Override public void handlePost(Operation post) { IPAddressState returnState = processInput(post); setState(post, returnState); post.complete(); }
@Override public void handlePost(Operation post) { IPAddressState returnState = processInput(post); logInfo("Resource %s was granted the ip %s with the status %s", returnState.connectedResourceLink, returnState.ipAddress, returnState.ipAddressStatus); ResourceUtils.populateTags(this, returnState) .thenAccept(__ -> setState(post, returnState)) .whenCompleteNotify(post); }
IPAddressState currentState = getState(patch); IPAddressState patchState = patch.getBody(IPAddressState.class); if (isNoOperation(currentState, patchState)) { patch.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED); patch.setBody(currentState); patchState.connectedResourceLink = ResourceUtils.NULL_LINK_VALUE; ResourceUtils.handlePatch(this, patch, currentState, getStateDescription(), IPAddressState.class, op -> { boolean hasChanged = false; logInfo("Validating transition for patch request from current ip %s " + "current status %s to new ip %s new status %s", currentState.ipAddress, currentState.ipAddressStatus, patchState.ipAddress, patchState.ipAddressStatus); validateIPAddressStatusTransition(currentState, patchState); currentState.ipAddressStatus = patchState.ipAddressStatus; validateIPAddressStatusWithConnectedResource(currentState); logInfo("Resource %s was granted the ip %s with the status %s", patchState.connectedResourceLink, patchState.ipAddress, patchState.ipAddressStatus); hasChanged = true;
IPAddressState currentState = getState(put); if (isNoOperation(currentState, newState)) { put.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED); put.setBody(currentState); validateState(newState); logInfo("Validating transition for put request from current ip %s " + "current status %s to new ip %s new status %s", currentState.ipAddress, currentState.ipAddressStatus, newState.ipAddress, newState.ipAddressStatus); validateIPAddressStatusTransition(currentState, newState); logInfo("Resource %s was granted the ip %s with the status %s", newState.connectedResourceLink, newState.ipAddress, newState.ipAddressStatus); .thenAccept(__ -> setState(put, newState)) .whenCompleteNotify(put); } catch (Throwable t) {
/** * @param op operation * @return a valid IPAddressState * @throws IllegalArgumentException if input invalid */ private IPAddressState processInput(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } IPAddressState state = op.getBody(IPAddressState.class); logInfo("Attempting to create IP %s for resource %s",state.ipAddress, state.connectedResourceLink); validateState(state); return state; }
private static void startFactoryServices(BaseModelTest test) throws Throwable { PhotonModelTaskServices.startServices(test.getHost()); MockAdapter.startFactories(test); test.getHost().startFactory(new IPAddressService()); }
@Override public void handleStart(Operation start) { processInput(start); start.complete(); }
/** * @param op operation * @return a valid IPAddressState * @throws IllegalArgumentException if input invalid */ private IPAddressState processInput(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } IPAddressState state = op.getBody(IPAddressState.class); validateState(state); return state; }
private static void startFactoryServices(BaseModelTest test) throws Throwable { PhotonModelTaskServices.startServices(test.getHost()); MockAdapter.startFactories(test); test.getHost().startFactory(new SubnetRangeService()); test.getHost().startFactory(new IPAddressService()); test.getHost().startFactory(new IPAddressAllocationTaskService()); }
@Override public void handleCreate(Operation start) { if (PhotonModelUtils.isFromMigration(start)) { start.complete(); return; } IPAddressState state = processInput(start); ResourceUtils.populateTags(this, state) .whenCompleteNotify(start); }
/** * Validation upon creation of an IP address object. * - valid IP address * No need to validate that the IP is within the range. * * @param state IpAddressState to validate * @throws IllegalArgumentException for invalid state */ private void validateState(IPAddressState state) { // Verify values based on the document description Utils.validateState(getStateDescription(), state); if (state.ipVersion == null) { state.ipVersion = DEFAULT_IP_VERSION; } if (!SubnetValidator.isValidIPAddress(state.ipAddress, state.ipVersion)) { throw new LocalizableValidationException(String.format("Invalid IP address: %s", state.ipAddress), "ip.address.invalid", state.ipAddress); } validateIPAddressStatusWithConnectedResource(state); logFine("Completed validation of IPAddressState: " + state); }
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()); } }