Search in sources :

Example 31 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestAWSImageEnumerationTask method testPrivateImageEnumeration_single.

/*
     * The image that must be returned:
     *
     * https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#Images:visibility=private-images;
     * imageId=ami-caf25eb0;sort=name
     *
     * under prelude_test @ https://537227425989.signin.aws.amazon.com/console
     */
@Test
@Ignore("https://jira-hzn.eng.vmware.com/browse/VCOM-832")
public void testPrivateImageEnumeration_single() throws Throwable {
    Assume.assumeFalse(this.isMock);
    final EndpointState endpointState = createEndpointState();
    kickOffImageEnumeration(endpointState, PRIVATE, AMAZON_PRIVATE_IMAGE_FILTER);
    // Validate 1 image state is CREATED
    ServiceDocumentQueryResult images = queryDocumentsAndAssertExpectedCount(getHost(), 1, ImageService.FACTORY_LINK, EXACT_COUNT);
    ImageState image = Utils.fromJson(images.documents.values().iterator().next(), ImageState.class);
    // Validate created image is correctly populated
    Assert.assertNull("Private image must NOT have endpointType set.", image.endpointType);
    Assert.assertEquals("Private image must have endpointLink set.", endpointState.documentSelfLink, image.endpointLink);
    Assert.assertEquals("Private image must have tenantLinks set.", endpointState.tenantLinks, image.tenantLinks);
    Assert.assertEquals("Private image id is incorrect.", "ami-caf25eb0", image.id);
    Assert.assertEquals("Private image name is incorrect.", "tapestryPipelineServiceTestService", image.name);
    Assert.assertEquals("Private image 'Name' tag is missing.", 1, image.tagLinks.size());
    TagState nameTag = getServiceSynchronously(image.tagLinks.iterator().next(), TagState.class);
    Assert.assertEquals(image.name, nameTag.value);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) Ignore(org.junit.Ignore) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 32 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestAWSSetupUtils method createAWSEndpointStateUsingAllocationTask.

/**
 * Create endpoint using EndpointAllocationTaskService.
 */
public static EndpointState createAWSEndpointStateUsingAllocationTask(VerificationHost host, String authLink, String resPoolLink, String accessKey, String secretKey, String endpointName) throws Throwable {
    EndpointState endpoint = createEndpointState(authLink, resPoolLink, accessKey, secretKey, endpointName);
    EndpointAllocationTaskState startState = createEndpointAllocationRequest(endpoint);
    EndpointAllocationTaskState returnState = TestUtils.doPost(host, startState, EndpointAllocationTaskState.class, UriUtils.buildUri(host, EndpointAllocationTaskService.FACTORY_LINK));
    EndpointAllocationTaskState completeState = host.waitForFinishedTask(EndpointAllocationTaskState.class, returnState.documentSelfLink);
    assertTrue(completeState.taskInfo.stage == TaskState.TaskStage.FINISHED);
    Operation response = host.waitForResponse(Operation.createGet(host, completeState.documentSelfLink));
    EndpointAllocationTaskState taskState = response.getBody(EndpointAllocationTaskState.class);
    assertNotNull(taskState.endpointState);
    ServiceDocument endpointState = taskState.endpointState;
    assertNotNull(endpointState.documentSelfLink);
    response = host.waitForResponse(Operation.createGet(host, endpointState.documentSelfLink));
    return response.getBody(EndpointState.class);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Operation(com.vmware.xenon.common.Operation)

Example 33 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class VSphereAdapterImageEnumerationService method thenWithEndpointState.

private void thenWithEndpointState(ImageEnumerateRequest request, EndpointState endpoint, TaskManager mgr) {
    URI parentUri = ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), endpoint.computeLink));
    Operation.createGet(PhotonModelUriUtils.createInventoryUri(getHost(), parentUri)).setCompletion(o -> thenWithParentState(request, o.getBody(ComputeStateWithDescription.class), mgr), mgr).sendWith(this);
}
Also used : PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RpcException(com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException) HashSet(java.util.HashSet) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) ImageService(com.vmware.photon.controller.model.resources.ImageService) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ObjectContent(com.vmware.vim25.ObjectContent) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) DatacenterLister(com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Set(java.util.Set) IOException(java.io.IOException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Phaser(java.util.concurrent.Phaser) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) ImageEnumerateRequest(com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) URI(java.net.URI)

Example 34 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AWSLoadBalancerServiceTest method createEndpointState.

private EndpointState createEndpointState() throws Throwable {
    EndpointState endpoint = new EndpointState();
    String endpointType = EndpointType.aws.name();
    endpoint.id = endpointType + "Id";
    endpoint.name = endpointType + "Name";
    endpoint.endpointType = endpointType;
    endpoint.tenantLinks = Collections.singletonList(endpointType + "Tenant");
    endpoint.authCredentialsLink = createAuthCredentialsState().documentSelfLink;
    endpoint.resourcePoolLink = "dummy";
    endpoint.regionId = this.regionId;
    return postServiceSynchronously(EndpointService.FACTORY_LINK, endpoint, EndpointState.class);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 35 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AWSInstanceTypeServiceTest method testGetInstanceTypesPositive.

@Test
public void testGetInstanceTypesPositive() throws Throwable {
    EndpointState ep = createEndpointState();
    TestContext ctx = this.host.testCreate(1);
    Operation getOperation = Operation.createGet(UriUtils.buildUri(this.host, AWSInstanceTypeService.SELF_LINK + "?endpoint=" + ep.documentSelfLink)).setCompletion((operation, throwable) -> {
        try {
            if (throwable != null) {
                ctx.failIteration(throwable);
                return;
            }
            assertEquals(Operation.STATUS_CODE_OK, operation.getStatusCode());
            InstanceTypeList instanceTypes = operation.getBody(InstanceTypeList.class);
            assertNotNull("Tenant links should ne set.", instanceTypes.tenantLinks);
            assertEquals("Tenant links size equal to endpoint tenant links size is " + "expecteed.", ep.tenantLinks.size(), instanceTypes.tenantLinks.size());
            assertNotNull("Instance types should not be null.", instanceTypes.instanceTypes);
            instanceTypes.instanceTypes.stream().filter(instanceType -> instanceType.id == null || instanceType.name == null).findFirst().ifPresent(instanceType -> fail("Found instance type without id " + "or name."));
            // Validate that all types have cpu and memory extended data set.
            instanceTypes.instanceTypes.stream().filter(instanceType -> instanceType.cpuCount == null || instanceType.memoryInMB == null).findFirst().ifPresent(instanceType -> fail("Found instance type without extended data present: " + instanceType.id));
            // Check that one of the well known type is present.
            InstanceTypeList.InstanceType t2MicroType = instanceTypes.instanceTypes.stream().filter(instanceType -> InstanceType.T2Micro.toString().equals(instanceType.id)).findFirst().orElseThrow(() -> new AssertionError("Unable to " + "find t2.micro instance type."));
            assertEquals(1, t2MicroType.cpuCount.intValue());
            assertEquals(1024, t2MicroType.memoryInMB.intValue());
            assertNotNull(t2MicroType.storageType);
            assertNotNull(t2MicroType.networkType);
            ctx.completeIteration();
        } catch (AssertionError err) {
            ctx.failIteration(err);
        }
    });
    this.send(getOperation);
    this.testWait(ctx);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TestContext(com.vmware.xenon.common.test.TestContext) Operation(com.vmware.xenon.common.Operation) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Aggregations

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)69 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)23 Operation (com.vmware.xenon.common.Operation)22 Test (org.junit.Test)16 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)13 URI (java.net.URI)13 HashMap (java.util.HashMap)13 Query (com.vmware.xenon.services.common.QueryTask.Query)12 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 List (java.util.List)11 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)10 ServiceDocument (com.vmware.xenon.common.ServiceDocument)10 Collectors (java.util.stream.Collectors)10 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9