use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class EndpointAdapterUtils method configureEndpoint.
private static void configureEndpoint(StatelessService service, EndpointConfigRequest body, BiConsumer<AuthCredentialsServiceState, Retriever> credEnhancer, BiConsumer<ComputeDescription, Retriever> descEnhancer, BiConsumer<ComputeState, Retriever> compEnhancer, BiConsumer<EndpointState, Retriever> endpointEnhancer) {
TaskManager tm = new TaskManager(service, body.taskReference, body.resourceLink());
Consumer<Throwable> onFailure = tm::patchTaskToFailure;
Consumer<Operation> onSuccess = (op) -> {
EndpointState endpoint = op.getBody(EndpointState.class);
op.complete();
AuthCredentialsServiceState authState = new AuthCredentialsServiceState();
Map<String, String> props = new HashMap<>(body.endpointProperties);
props.put(MOCK_REQUEST, String.valueOf(body.isMockRequest));
props.put(ENDPOINT_REFERENCE_URI, body.resourceReference.toString());
Retriever r = Retriever.of(props);
try {
credEnhancer.accept(authState, r);
ComputeDescription cd = new ComputeDescription();
descEnhancer.accept(cd, r);
ComputeState cs = new ComputeState();
cs.powerState = PowerState.ON;
compEnhancer.accept(cs, r);
EndpointState es = new EndpointState();
es.endpointProperties = new HashMap<>();
es.regionId = r.get(EndpointConfigRequest.REGION_KEY).orElse(null);
endpointEnhancer.accept(es, r);
Stream<Operation> operations = Stream.of(Pair.of(authState, endpoint.authCredentialsLink), Pair.of(cd, endpoint.computeDescriptionLink), Pair.of(cs, endpoint.computeLink), Pair.of(es, endpoint.documentSelfLink)).map((p) -> Operation.createPatch(createInventoryUri(service.getHost(), p.right)).setBody(p.left).setReferer(service.getUri()));
applyChanges(tm, service, endpoint, operations);
} catch (Exception e) {
tm.patchTaskToFailure(e);
}
};
AdapterUtils.getServiceState(service, body.resourceReference, onSuccess, onFailure);
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class EndpointAdapterUtils method getEndpointLinks.
private static DeferredResult<List<String>> getEndpointLinks(ServiceHost host, Query endpointQuery, List<String> credentialsLinks, String endpointType, List<String> queryTaskTenantLinks) {
if (credentialsLinks.isEmpty()) {
return DeferredResult.completed(Collections.emptyList());
}
Query.Builder qBuilder = Builder.create().addKindFieldClause(EndpointState.class).addFieldClause(EndpointState.FIELD_NAME_ENDPOINT_TYPE, endpointType).addInClause(EndpointState.FIELD_NAME_AUTH_CREDENTIALS_LINK, credentialsLinks);
if (endpointQuery != null) {
qBuilder.addClause(endpointQuery);
}
QueryTop<EndpointState> queryEndpoints = new QueryTop<>(host, qBuilder.build(), EndpointState.class, queryTaskTenantLinks).setQueryTaskTenantLinks(queryTaskTenantLinks).setMaxResultsLimit(1);
queryEndpoints.setClusterType(INVENTORY_SERVICE);
return queryEndpoints.collectLinks(Collectors.toList());
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionEndpointsEnumerationServiceTest method testAddSecondAzureSubscription.
private void testAddSecondAzureSubscription() throws Throwable {
// Request for creating computes for 1 Azure Subscriptions
AzureSubscription subscription = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_ID_2);
createAzureEndpointsForSubscriptions(Collections.singletonList(subscription));
// Query the Endpoints to assert
ServiceDocumentQueryResult result = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
Assert.assertEquals(3, result.documents.size());
// Assert the created Endpoint and other resources
result.documents.remove(this.endpointLink);
// Remove the endpoints created earlier
this.createdEndpointLinks.forEach(endpoint -> result.documents.remove(endpoint));
EndpointState endpointStateCreated = Utils.fromJson(result.documents.values().iterator().next(), EndpointState.class);
assertCreatedEndpoint(endpointStateCreated, SUBSCRIPTION_ID_2);
this.createdEndpointLinks.add(endpointStateCreated.documentSelfLink);
// Assert the root compute under the endpoint
ComputeState computeStateCreated = getServiceSynchronously(endpointStateCreated.computeLink, ComputeState.class);
assertCreatedComputeState(computeStateCreated, SUBSCRIPTION_ID_2, ACCOUNT_ID_2);
// Assert the partial AuthCredentialsState
AuthCredentialsServiceState authCreated = getServiceSynchronously(endpointStateCreated.authCredentialsLink, AuthCredentialsServiceState.class);
assertAuthCredentialState(authCreated, SUBSCRIPTION_ID_2);
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionEndpointsEnumerationServiceTest method setUp.
@Before
public void setUp() throws Exception {
this.host = VerificationHost.create(0);
this.isMock = true;
this.createdEndpointLinks = new ArrayList<>();
try {
this.host.start();
PhotonModelServices.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
this.host.startService(new AzureSubscriptionEndpointsEnumerationService());
AzureAdaptersTestUtils.startServicesSynchronouslyEaAzure(this.host);
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelMetricServices.LINKS);
this.host.waitForServiceAvailable(AzureSubscriptionEndpointsEnumerationService.SELF_LINK);
this.host.setTimeoutSeconds(600);
// Create an Azure endpoint which will act as Azure EA endpoint
EndpointState ep = createEndpointState();
EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
validateEndpoint.endpointState = ep;
validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
validateEndpoint.tenantLinks = Collections.singletonList(TENANT_ID);
EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
EndpointAllocationTaskState taskState = getServiceSynchronously(outTask.documentSelfLink, EndpointAllocationTaskState.class);
this.endpointLink = taskState.endpointState.documentSelfLink;
this.computeLink = taskState.endpointState.computeLink;
this.compute = getServiceSynchronously(this.computeLink, ComputeState.class);
} catch (Throwable e) {
throw new Exception(e);
}
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionEndpointCreationServiceTest method setUp.
@Before
public void setUp() throws Exception {
try {
this.host.setMaintenanceIntervalMicros(TimeUnit.MILLISECONDS.toMicros(10));
PhotonModelServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
this.host.startService(new AzureSubscriptionEndpointCreationService());
AzureAdaptersTestUtils.startServicesSynchronouslyEaAzure(this.host);
this.host.setTimeoutSeconds(300);
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
this.host.waitForServiceAvailable(AzureSubscriptionEndpointCreationService.SELF_LINK);
EndpointState ep = createEndpointState();
// Create the Azure Ea Endpoint for the test
EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
validateEndpoint.endpointState = ep;
validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
validateEndpoint.tenantLinks = Collections.singletonList(TENANT_ID);
EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
EndpointAllocationTaskState taskState = getServiceSynchronously(outTask.documentSelfLink, EndpointAllocationTaskState.class);
this.eaEndPointLink = taskState.endpointState.documentSelfLink;
} catch (Throwable e) {
throw new Exception(e);
}
}
Aggregations