private NetworkInterfaceDescription validatePut(Operation op) { NetworkInterfaceDescription state = processInput(op); NetworkInterfaceDescription currentState = getState(op); ResourceUtils.validatePut(state, currentState); return state; }
@Override public void handlePut(Operation put) { NetworkInterfaceDescription returnState = processInput(put); setState(put, returnState); put.complete(); }
private NetworkInterfaceDescription processInput(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } NetworkInterfaceDescription state = op.getBody(NetworkInterfaceDescription.class); validateState(state); return state; }
@Override public void handlePatch(Operation patch) { NetworkInterfaceDescription currentState = getState(patch); ResourceUtils.handlePatch(this, patch, currentState, getStateDescription(), NetworkInterfaceDescription.class, t -> { NetworkInterfaceDescription patchBody = patch.getBody(NetworkInterfaceDescription.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; }); }
@Override public void handlePut(Operation put) { if (PhotonModelUtils.isFromMigration(put)) { super.handlePut(put); return; } NetworkInterfaceDescription returnState = validatePut(put); ResourceUtils.populateTags(this, returnState) .thenAccept(__ -> setState(put, returnState)) .whenCompleteNotify(put); }
@Override public void handleStart(Operation start) { processInput(start); start.complete(); }
private void validateState(NetworkInterfaceDescription state) { if (state.assignment == null) { state.assignment = IpAssignment.DYNAMIC; } Utils.validateState(getStateDescription(), state); if (state.address != null) { if (state.assignment != IpAssignment.STATIC) { throw new IllegalArgumentException( "IP can be reserved only when assignment is STATIC"); } if (!InetAddressValidator.getInstance().isValidInet4Address( state.address)) { throw new IllegalArgumentException("IP address is invalid"); } } }
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 handlePatch(Operation patch) { NetworkInterfaceDescription currentState = getState(patch); ResourceUtils.handlePatch(patch, currentState, getStateDescription(), NetworkInterfaceDescription.class, t -> { NetworkInterfaceDescription patchBody = patch.getBody(NetworkInterfaceDescription.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; }); }
@Override public void handleCreate(Operation start) { if (PhotonModelUtils.isFromMigration(start)) { start.complete(); return; } NetworkInterfaceDescription state = processInput(start); state.documentCreationTimeMicros = Utils.getNowMicrosUtc(); ResourceUtils.populateTags(this, state) .whenCompleteNotify(start); }
private void validateState(NetworkInterfaceDescription state) { if (state.assignment == null) { state.assignment = IpAssignment.DYNAMIC; } Utils.validateState(getStateDescription(), state); if (state.address != null) { if (state.assignment != IpAssignment.STATIC) { throw new IllegalArgumentException( "IP can be reserved only when assignment is STATIC"); } if (!InetAddressValidator.getInstance().isValidInet4Address( state.address)) { throw new IllegalArgumentException("IP address is invalid"); } } }
private NetworkInterfaceDescription processInput(Operation op) { if (!op.hasBody()) { throw (new IllegalArgumentException("body is required")); } NetworkInterfaceDescription state = op.getBody(NetworkInterfaceDescription.class); validateState(state); return state; }