use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class EndpointAllocationTaskServiceTest method createEndpointState.
private static EndpointState createEndpointState() {
EndpointState endpoint = new EndpointState();
endpoint.endpointType = EndpointType.aws.name();
endpoint.name = "aws_endpoint";
endpoint.endpointProperties = new HashMap<>();
endpoint.endpointProperties.put(REGION_KEY, "test-regionId");
endpoint.endpointProperties.put(PRIVATE_KEY_KEY, TEST_SECRETE_KEY);
endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, TEST_ACCESS_KEY);
endpoint.tenantLinks = Collections.singletonList("tenant-1");
return endpoint;
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class EndpointServiceTests method testCreateEndpoint.
public void testCreateEndpoint(EndpointService.EndpointState ep) throws Throwable {
EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
validateEndpoint.endpointState = ep;
validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
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);
assertNotNull(taskState);
assertNotNull(taskState.endpointState);
ServiceDocument endpointState = taskState.endpointState;
assertNotNull(endpointState.documentSelfLink);
// check endpoint document was created
EndpointService.EndpointState endpoint = getServiceSynchronously(endpointState.documentSelfLink, EndpointService.EndpointState.class);
assertNotNull(endpoint);
assertNotNull(endpoint.authCredentialsLink);
assertNotNull(endpoint.computeLink);
assertNotNull(endpoint.computeDescriptionLink);
AuthCredentialsService.AuthCredentialsServiceState credentials = getServiceSynchronously(endpoint.authCredentialsLink, AuthCredentialsService.AuthCredentialsServiceState.class);
assertNotNull(credentials);
assertEquals(ep.endpointProperties.get(PRIVATE_KEYID_KEY), credentials.privateKeyId);
assertEquals(ep.endpointProperties.get(PRIVATE_KEY_KEY), credentials.privateKey);
ComputeDescriptionService.ComputeDescription cd = getServiceSynchronously(endpoint.computeDescriptionLink, ComputeDescriptionService.ComputeDescription.class);
assertNotNull(cd);
assertEquals(credentials.documentSelfLink, cd.authCredentialsLink);
assertEquals(this.regionId, cd.regionId);
assertEquals(this.environmentName, cd.environmentName);
ComputeService.ComputeState cs = getServiceSynchronously(endpoint.computeLink, ComputeService.ComputeState.class);
assertNotNull(cs);
assertNotNull(cs.adapterManagementReference);
assertEquals(ComputeDescriptionService.ComputeDescription.ComputeType.ENDPOINT_HOST, cs.type);
assertEquals(this.environmentName, cs.environmentName);
assertEquals(ComputeService.PowerState.ON, cs.powerState);
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class ResourceGroomerTaskService method collectDeletedEndpoints.
/**
* Get endpointLinks for all documents and collect deleted endpointLinks by querying for all links
* with INCLUDE_DELETED.
*/
private void collectDeletedEndpoints(EndpointResourceDeletionRequest task, SubStage next) {
QueryTask queryTask;
// from all documents and query for those.
if (isEndpointSpecified(task)) {
queryTask = buildQueryTask(task, true, Collections.singleton(task.endpointLink));
} else {
Set<String> currentEndpointLinks = new HashSet<>();
task.endpointLinksByDocumentLinks.values().stream().forEach(links -> {
currentEndpointLinks.addAll(links);
});
currentEndpointLinks.addAll(task.endpointLinkByDocumentLinks.values());
if (currentEndpointLinks.isEmpty()) {
task.subStage = next;
sendSelfPatch(task);
return;
}
queryTask = buildQueryTask(task, true, currentEndpointLinks);
}
QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((response, e) -> {
if (e != null) {
task.failureMessage = e.getMessage();
task.subStage = SubStage.FAILED;
sendSelfPatch(task);
return;
}
if (response.results != null && response.results.documents != null) {
response.results.documents.values().stream().forEach(obj -> {
EndpointState state = Utils.fromJson(obj, EndpointState.class);
if (state.documentUpdateAction.equals(Action.DELETE.name())) {
task.deletedEndpointLinks.add(state.documentSelfLink);
}
});
}
if (response.results != null && response.results.nextPageLink != null) {
processDeletedEndpointLinksQueryPage(task, response.results.nextPageLink, next);
return;
}
task.subStage = next;
sendSelfPatch(task);
});
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class EndpointAllocationTaskService method updateOrCreateEndpoint.
private void updateOrCreateEndpoint(EndpointAllocationTaskState currentState) {
EndpointState es = currentState.endpointState;
Map<String, String> endpointProperties = currentState.endpointState.endpointProperties;
es.endpointProperties = null;
Operation.createPatch(this, es.documentSelfLink).setBody(es).setCompletion((o, e) -> {
if (e != null) {
if (o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) {
logInfo(() -> String.format("Endpoint %s not found, creating new.", es.documentSelfLink));
currentState.endpointState.endpointProperties = endpointProperties;
createEndpoint(currentState);
} else {
logSevere(() -> String.format("Failed to update endpoint %s : %s", es.documentSelfLink, e.getMessage()));
sendFailurePatch(this, currentState, e);
}
return;
}
EndpointState loadedState = o.getBody(EndpointState.class);
loadedState.endpointProperties = endpointProperties;
EndpointAllocationTaskState state = createUpdateSubStageTask(SubStage.INVOKE_ADAPTER);
state.endpointState = loadedState;
List<Operation> patchOperations = new ArrayList<>();
if (es.computeDescriptionLink != null) {
Operation compDescOp = Operation.createPatch(this, es.computeDescriptionLink).setBody(configureDescriptionPatch(es));
patchOperations.add(compDescOp);
}
if (es.computeLink != null) {
Operation computeOp = Operation.createPatch(this, es.computeLink).setBody(configureComputePatch(es, es.endpointProperties));
patchOperations.add(computeOp);
}
if (patchOperations.size() == 0) {
sendSelfPatch(state);
return;
}
OperationJoin.create(patchOperations).setCompletion((ops, failures) -> {
if (failures != null) {
long firstKey = failures.keySet().iterator().next();
failures.values().forEach(ex -> logWarning(() -> String.format("Error executing patch " + "operations while creating/updating " + "endpoint: %s", ex.getMessage())));
sendFailurePatch(this, currentState, failures.get(firstKey));
return;
}
sendSelfPatch(state);
}).sendWith(this);
}).sendWith(this);
}
Aggregations