@Override public void handlePatch(Operation patch) { NetworkInterfaceState currentState = getState(patch); ResourceUtils.handlePatch(this, patch, currentState, getStateDescription(), NetworkInterfaceState.class, t -> { NetworkInterfaceState patchBody = patch.getBody(NetworkInterfaceState.class); boolean hasStateChanged = false; if (patchBody.endpointLink != null && currentState.endpointLink == null) { currentState.endpointLink = patchBody.endpointLink; hasStateChanged = true; } if (patchBody.securityGroupLinks != null) { if (currentState.securityGroupLinks == null) { currentState.securityGroupLinks = patchBody.securityGroupLinks; hasStateChanged = true; } else { for (String link : patchBody.securityGroupLinks) { if (!currentState.securityGroupLinks.contains(link)) { currentState.securityGroupLinks.add(link); hasStateChanged = true; } } } } return hasStateChanged; }); }
private NetworkInterfaceState validatePut(Operation op) { NetworkInterfaceState state = processInput(op); NetworkInterfaceState currentState = getState(op); ResourceUtils.validatePut(state, currentState); return state; }
@Override public void handlePut(Operation put) { try { NetworkInterfaceState returnState = processInput(put); setState(put, returnState); put.complete(); } catch (Throwable t) { put.fail(t); } }
@Override public void handleGet(Operation get) { NetworkInterfaceState 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.networkInterfaceDescriptionLink) .setCompletion( (o, e) -> { if (e != null) { get.fail(e); return; } NetworkInterfaceDescription desc = o .getBody(NetworkInterfaceDescription.class); NetworkInterfaceStateWithDescription stateWithDesc = NetworkInterfaceStateWithDescription .create(desc, currentState); get.setBody(stateWithDesc).complete(); }); sendRequest(getDesc); }
@Override public void handlePut(Operation put) { if (PhotonModelUtils.isFromMigration(put)) { super.handlePut(put); return; } NetworkInterfaceState returnState = validatePut(put); ResourceUtils.populateTags(this, returnState) .thenAccept(__ -> setState(put, returnState)) .whenCompleteNotify(put); }
@Override public void handleStart(Operation start) { try { processInput(start); start.complete(); } catch (Throwable t) { start.fail(t); } }
private NetworkInterfaceState processInput(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } NetworkInterfaceState state = op.getBody(NetworkInterfaceState.class); validateState(state); return state; }
private void validateState(NetworkInterfaceState state) { Utils.validateState(getStateDescription(), state); if (state.address != null) { if (!InetAddressValidator.getInstance().isValidInet4Address( state.address)) { throw new IllegalArgumentException("IP address is invalid"); } } if (state.networkLink == null && state.subnetLink == null) { throw new IllegalArgumentException( "Either subnetLink or networkLink must be set"); } } }
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) { NetworkInterfaceState 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.networkInterfaceDescriptionLink) .setCompletion( (o, e) -> { if (e != null) { get.fail(e); return; } NetworkInterfaceDescription desc = o .getBody(NetworkInterfaceDescription.class); NetworkInterfaceStateWithDescription stateWithDesc = NetworkInterfaceStateWithDescription .create(desc, currentState); get.setBody(stateWithDesc).complete(); }); sendRequest(getDesc); }
@Override public void handleCreate(Operation start) { if (PhotonModelUtils.isFromMigration(start)) { start.complete(); return; } NetworkInterfaceState state = processInput(start); state.documentCreationTimeMicros = Utils.getNowMicrosUtc(); ResourceUtils.populateTags(this, state) .whenCompleteNotify(start); }
private NetworkInterfaceState processInput(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } NetworkInterfaceState state = op.getBody(NetworkInterfaceState.class); validateState(state); return state; }
private void validateState(NetworkInterfaceState state) { Utils.validateState(getStateDescription(), state); if (state.address != null) { if (state.subnetLink == null) { throw new IllegalArgumentException( "SubnetLink must not be null when address is set"); } if (!InetAddressValidator.getInstance().isValidInet4Address( state.address)) { throw new IllegalArgumentException("IP address is invalid"); } } if (state.networkLink == null && state.subnetLink == null) { throw new IllegalArgumentException( "Either subnetLink or networkLink must be set"); } } }
@Override public void handlePatch(Operation patch) { NetworkInterfaceState currentState = getState(patch); ResourceUtils.handlePatch(patch, currentState, getStateDescription(), NetworkInterfaceState.class, t -> { NetworkInterfaceState patchBody = patch.getBody(NetworkInterfaceState.class); boolean hasStateChanged = false; if (patchBody.endpointLink != null && currentState.endpointLink == null) { currentState.endpointLink = patchBody.endpointLink; hasStateChanged = true; } if (patchBody.securityGroupLinks != null) { if (currentState.securityGroupLinks == null) { currentState.securityGroupLinks = patchBody.securityGroupLinks; hasStateChanged = true; } else { for (String link : patchBody.securityGroupLinks) { if (!currentState.securityGroupLinks.contains(link)) { currentState.securityGroupLinks.add(link); hasStateChanged = true; } } } } return hasStateChanged; }); }