Search in sources :

Example 56 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class BaseVSphereAdapterTest method createAuth.

protected AuthCredentialsServiceState createAuth() throws Throwable {
    AuthCredentialsServiceState auth = new AuthCredentialsServiceState();
    auth.type = DEFAULT_AUTH_TYPE;
    auth.privateKeyId = this.vcUsername;
    auth.privateKey = this.vcPassword;
    auth.documentSelfLink = UUID.randomUUID().toString();
    AuthCredentialsServiceState result = TestUtils.doPost(this.host, auth, AuthCredentialsServiceState.class, UriUtils.buildUri(this.host, AuthCredentialsService.FACTORY_LINK));
    return result;
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 57 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class ProvisionContext method populateContextThen.

/**
 * Populates the given initial context and invoke the onSuccess handler when built. At every step,
 * if failure occurs the ProvisionContext's errorHandler is invoked to cleanup.
 *
 * @param ctx
 * @param onSuccess
 */
public static void populateContextThen(Service service, ProvisionContext ctx, Consumer<ProvisionContext> onSuccess) {
    // TODO fetch all required state in parallel using OperationJoin.
    if (ctx.child == null) {
        URI computeUri = UriUtils.extendUriWithQuery(ctx.computeReference, UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
        computeUri = createInventoryUri(service.getHost(), computeUri);
        AdapterUtils.getServiceState(service, computeUri, op -> {
            ctx.child = op.getBody(ComputeStateWithDescription.class);
            populateContextThen(service, ctx, onSuccess);
        }, ctx.errorHandler);
        return;
    }
    String templateLink = VimUtils.firstNonNull(CustomProperties.of(ctx.child).getString(CustomProperties.TEMPLATE_LINK), CustomProperties.of(ctx.child.description).getString(CustomProperties.TEMPLATE_LINK));
    // in all other cases ignore the presence of the template
    if (templateLink != null && ctx.templateMoRef == null && ctx.instanceRequestType == InstanceRequestType.CREATE) {
        URI computeUri = createInventoryUri(service.getHost(), templateLink);
        AdapterUtils.getServiceState(service, computeUri, op -> {
            ImageState body = op.getBody(ImageState.class);
            ctx.templateMoRef = CustomProperties.of(body).getMoRef(CustomProperties.MOREF);
            if (ctx.templateMoRef == null) {
                String msg = String.format("The linked template %s does not contain a MoRef in its custom properties", templateLink);
                ctx.fail(new IllegalStateException(msg));
            } else {
                populateContextThen(service, ctx, onSuccess);
            }
        }, ctx.errorHandler);
        return;
    }
    // For creation based on linked clone of snapshot
    if (ctx.snapshotMoRef == null) {
        String snapshotLink = CustomProperties.of(ctx.child).getString(CustomProperties.SNAPSHOT_LINK);
        if (snapshotLink != null && ctx.instanceRequestType == InstanceRequestType.CREATE) {
            URI snapshotUri = createInventoryUri(service.getHost(), snapshotLink);
            AdapterUtils.getServiceState(service, snapshotUri, op -> {
                SnapshotService.SnapshotState snapshotState = op.getBody(SnapshotService.SnapshotState.class);
                ctx.snapshotMoRef = CustomProperties.of(snapshotState).getMoRef(CustomProperties.MOREF);
                if (ctx.snapshotMoRef == null) {
                    String msg = String.format("The linked clone snapshot %s does not contain a MoRef in its custom properties", snapshotLink);
                    ctx.fail(new IllegalStateException(msg));
                } else {
                    // Retrieve the reference endpoint moref from which the linkedclone has to be created.
                    String refComputeLink = snapshotState.computeLink;
                    if (refComputeLink != null) {
                        URI refComputeUri = createInventoryUri(service.getHost(), refComputeLink);
                        AdapterUtils.getServiceState(service, refComputeUri, opCompute -> {
                            ComputeStateWithDescription refComputeState = opCompute.getBody(ComputeStateWithDescription.class);
                            ctx.referenceComputeMoRef = CustomProperties.of(refComputeState).getMoRef(CustomProperties.MOREF);
                            if (ctx.referenceComputeMoRef == null) {
                                String msg = String.format("The linked clone endpoint ref %s does not contain a MoRef in its custom properties", refComputeLink);
                                ctx.fail(new IllegalStateException(msg));
                            }
                            populateContextThen(service, ctx, onSuccess);
                        }, ctx.errorHandler);
                    }
                }
            }, ctx.errorHandler);
            return;
        }
    }
    if (ctx.parent == null && ctx.child.parentLink != null) {
        URI computeUri = UriUtils.extendUriWithQuery(UriUtils.buildUri(service.getHost(), ctx.child.parentLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
        computeUri = createInventoryUri(service.getHost(), computeUri);
        AdapterUtils.getServiceState(service, computeUri, op -> {
            ctx.parent = op.getBody(ComputeStateWithDescription.class);
            populateContextThen(service, ctx, onSuccess);
        }, ctx.errorHandler);
        return;
    }
    if (ctx.vSphereCredentials == null) {
        if (IAAS_API_ENABLED) {
            if (ctx.operation == null) {
                ctx.fail(new IllegalArgumentException("Caller operation cannot be empty"));
                return;
            }
            SessionUtil.retrieveExternalToken(service, ctx.operation.getAuthorizationContext()).whenComplete((authCredentialsServiceState, throwable) -> {
                if (throwable != null) {
                    ctx.errorHandler.accept(throwable);
                    return;
                }
                ctx.vSphereCredentials = authCredentialsServiceState;
                populateContextThen(service, ctx, onSuccess);
            });
        } else {
            if (ctx.parent.description.authCredentialsLink == null) {
                ctx.fail(new IllegalStateException("authCredentialsLink is not defined in resource " + ctx.parent.description.documentSelfLink));
                return;
            }
            URI credUri = createInventoryUri(service.getHost(), ctx.parent.description.authCredentialsLink);
            AdapterUtils.getServiceState(service, credUri, op -> {
                ctx.vSphereCredentials = op.getBody(AuthCredentialsServiceState.class);
                populateContextThen(service, ctx, onSuccess);
            }, ctx.errorHandler);
        }
        return;
    }
    if (ctx.task == null) {
        // Verify if this makes sense? These tasks should always be local to deployment?
        AdapterUtils.getServiceState(service, ctx.provisioningTaskReference, op -> {
            ctx.task = op.getBody(ServiceDocument.class);
            populateContextThen(service, ctx, onSuccess);
        }, ctx.errorHandler);
        return;
    }
    if (ctx.nics == null && ctx.instanceRequestType == InstanceRequestType.CREATE) {
        if (ctx.child.networkInterfaceLinks == null || ctx.child.networkInterfaceLinks.isEmpty()) {
            ctx.nics = Collections.emptyList();
            populateContextThen(service, ctx, onSuccess);
            return;
        }
        ctx.nics = new ArrayList<>();
        Query query = Query.Builder.create().addInClause(ServiceDocument.FIELD_NAME_SELF_LINK, ctx.child.networkInterfaceLinks).build();
        QueryTask qt = QueryTask.Builder.createDirectTask().setQuery(query).addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.EXPAND_LINKS).addOption(QueryOption.SELECT_LINKS).addOption(QueryOption.INDEXED_METADATA).addLinkTerm(NetworkInterfaceState.FIELD_NAME_NETWORK_LINK).addLinkTerm(NetworkInterfaceState.FIELD_NAME_SUBNET_LINK).addLinkTerm(NetworkInterfaceState.FIELD_NAME_DESCRIPTION_LINK).build();
        QueryUtils.startInventoryQueryTask(service, qt).whenComplete((o, e) -> {
            if (e != null) {
                ctx.errorHandler.accept(e);
                return;
            }
            QueryResultsProcessor processor = QueryResultsProcessor.create(o);
            for (NetworkInterfaceStateWithDetails nic : processor.documents(NetworkInterfaceStateWithDetails.class)) {
                if (nic.networkInterfaceDescriptionLink != null) {
                    NetworkInterfaceDescription desc = processor.selectedDocument(nic.networkInterfaceDescriptionLink, NetworkInterfaceDescription.class);
                    nic.description = desc;
                }
                if (nic.subnetLink != null) {
                    SubnetState subnet = processor.selectedDocument(nic.subnetLink, SubnetState.class);
                    nic.subnet = subnet;
                }
                if (nic.networkLink != null) {
                    NetworkState network = processor.selectedDocument(nic.networkLink, NetworkState.class);
                    nic.network = network;
                }
                ctx.nics.add(nic);
            }
            populateContextThen(service, ctx, onSuccess);
        });
        return;
    }
    if (ctx.computeMoRef == null) {
        String placementLink = CustomProperties.of(ctx.child).getString(ComputeProperties.PLACEMENT_LINK);
        if (placementLink == null) {
            Exception error = new IllegalStateException("A Compute resource must have a " + ComputeProperties.PLACEMENT_LINK + " custom property");
            ctx.fail(error);
            return;
        }
        URI expandedPlacementUri = UriUtils.extendUriWithQuery(createInventoryUri(service.getHost(), placementLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
        expandedPlacementUri = createInventoryUri(service.getHost(), expandedPlacementUri);
        Operation.createGet(expandedPlacementUri).setCompletion((o, e) -> {
            if (e != null) {
                ctx.fail(e);
                return;
            }
            ComputeStateWithDescription host = o.getBody(ComputeStateWithDescription.class);
            // extract the target resource pool for the placement
            CustomProperties hostCustomProperties = CustomProperties.of(host);
            ctx.computeMoRef = hostCustomProperties.getMoRef(CustomProperties.MOREF);
            if (ctx.computeMoRef == null) {
                Exception error = new IllegalStateException(String.format("Compute @ %s does not contain a %s custom property", placementLink, CustomProperties.MOREF));
                ctx.fail(error);
                return;
            }
            if (host.description.regionId == null) {
                Exception error = new IllegalStateException(String.format("Compute @ %s does not specify a region", placementLink));
                ctx.fail(error);
                return;
            }
            try {
                ctx.datacenterMoRef = VimUtils.convertStringToMoRef(host.description.regionId);
            } catch (IllegalArgumentException ex) {
                ctx.fail(ex);
                return;
            }
            populateContextThen(service, ctx, onSuccess);
        }).sendWith(service);
        return;
    }
    if (ctx.disks == null) {
        // no disks attached
        if (ctx.child.diskLinks == null || ctx.child.diskLinks.isEmpty()) {
            ctx.disks = Collections.emptyList();
            populateContextThen(service, ctx, onSuccess);
            return;
        }
        ctx.disks = new ArrayList<>(ctx.child.diskLinks.size());
        // collect disks in parallel
        Stream<Operation> opsGetDisk = ctx.child.diskLinks.stream().map(link -> {
            URI diskStateUri = UriUtils.buildUri(service.getHost(), link);
            return Operation.createGet(createInventoryUri(service.getHost(), DiskStateExpanded.buildUri(diskStateUri)));
        });
        OperationJoin join = OperationJoin.create(opsGetDisk).setCompletion((os, errors) -> {
            if (errors != null && !errors.isEmpty()) {
                // fail on first error
                ctx.errorHandler.accept(new IllegalStateException("Cannot get disk state", errors.values().iterator().next()));
                return;
            }
            os.values().forEach(op -> ctx.disks.add(op.getBody(DiskStateExpanded.class)));
            populateContextThen(service, ctx, onSuccess);
        });
        join.sendWith(service);
        return;
    }
    String libraryItemLink = VimUtils.firstNonNull(CustomProperties.of(ctx.child).getString(CustomProperties.LIBRARY_ITEM_LINK), CustomProperties.of(ctx.child.description).getString(CustomProperties.LIBRARY_ITEM_LINK));
    if (libraryItemLink != null && ctx.image == null && ctx.instanceRequestType == InstanceRequestType.CREATE) {
        URI libraryUri = createInventoryUri(service.getHost(), libraryItemLink);
        AdapterUtils.getServiceState(service, libraryUri, op -> {
            ImageState body = op.getBody(ImageState.class);
            ctx.image = body;
            populateContextThen(service, ctx, onSuccess);
        }, ctx.errorHandler);
        return;
    }
    if (ctx.instanceRequestType == InstanceRequestType.CREATE) {
        if (ctx.image == null) {
            DiskStateExpanded bootDisk = ctx.disks.stream().filter(d -> d.imageLink != null).findFirst().orElse(null);
            if (bootDisk != null) {
                URI bootImageRef = createInventoryUri(service.getHost(), bootDisk.imageLink);
                AdapterUtils.getServiceState(service, bootImageRef, op -> {
                    ImageState body = op.getBody(ImageState.class);
                    ctx.image = body;
                    populateContextThen(service, ctx, onSuccess);
                }, ctx.errorHandler);
                return;
            }
        }
    }
    // Order networks by deviceIndex so that nics are created in the same order
    if (ctx.nics != null) {
        // configure network
        ctx.nics.sort((lnis, rnis) -> {
            return Integer.compare(lnis.deviceIndex, rnis.deviceIndex);
        });
    }
    // context populated, invoke handler
    onSuccess.accept(ctx);
}
Also used : Service(com.vmware.xenon.common.Service) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) SessionUtil(com.vmware.photon.controller.model.resources.SessionUtil) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) ArrayList(java.util.ArrayList) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) ResourceRequest(com.vmware.photon.controller.model.adapterapi.ResourceRequest) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) URI(java.net.URI) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest.InstanceRequestType) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) UriUtils(com.vmware.xenon.common.UriUtils) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) IAAS_API_ENABLED(com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) Query(com.vmware.xenon.services.common.QueryTask.Query) OperationJoin(com.vmware.xenon.common.OperationJoin) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) ServiceDocument(com.vmware.xenon.common.ServiceDocument) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QueryTask(com.vmware.xenon.services.common.QueryTask) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 58 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AWSLoadBalancerServiceTest method createAuthCredentialsState.

private AuthCredentialsServiceState createAuthCredentialsState() throws Throwable {
    AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
    creds.privateKey = this.secretKey;
    creds.privateKeyId = this.accessKey;
    return postServiceSynchronously(AuthCredentialsService.FACTORY_LINK, creds, AuthCredentialsServiceState.class);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 59 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AWSLoadBalancerServiceTest method setUp.

@Override
@Before
public void setUp() throws Throwable {
    CommandLineArgumentParser.parseFromProperties(this);
    try {
        PhotonModelServices.startServices(this.host);
        PhotonModelMetricServices.startServices(this.host);
        PhotonModelTaskServices.startServices(this.host);
        PhotonModelAdaptersRegistryAdapters.startServices(this.host);
        AWSAdaptersTestUtils.startServicesSynchronously(this.host);
        AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
        creds.privateKey = this.secretKey;
        creds.privateKeyId = this.accessKey;
        TestContext lbWaitContext = new TestContext(1, Duration.ofSeconds(30L));
        AWSUtils.getAwsLoadBalancingAsyncClient(creds, this.regionId, getExecutor()).exceptionally(t -> {
            lbWaitContext.fail(t);
            throw new CompletionException(t);
        }).thenAccept(ec2Client -> {
            this.client = ec2Client;
            lbWaitContext.complete();
        });
        lbWaitContext.await();
        TestContext ec2WaitContext = new TestContext(1, Duration.ofSeconds(30L));
        AWSUtils.getEc2AsyncClient(creds, this.regionId, getExecutor()).exceptionally(t -> {
            ec2WaitContext.fail(t);
            throw new CompletionException(t);
        }).thenAccept(ec2Client -> {
            this.ec2client = ec2Client;
            ec2WaitContext.complete();
        });
        ec2WaitContext.await();
        TestContext secGroupWaitContext = new TestContext(1, Duration.ofSeconds(30L));
        AWSUtils.getEc2AsyncClient(creds, this.regionId, getExecutor()).exceptionally(t -> {
            secGroupWaitContext.fail(t);
            throw new CompletionException(t);
        }).thenAccept(ec2Client -> {
            this.securityGroupClient = new AWSSecurityGroupClient(ec2Client);
            secGroupWaitContext.complete();
        });
        secGroupWaitContext.await();
        this.host.setTimeoutSeconds(this.timeoutSeconds);
        this.endpointState = createEndpointState();
        String vm1 = "vm1";
        String vm2 = "vm2";
        if (!this.isMock) {
            vm1 = provisionAWSVMWithEC2Client(this.host, this.ec2client, EC2_LINUX_AMI, this.subnetId, null);
            this.instancesToCleanUp.add(vm1);
            vm2 = provisionAWSVMWithEC2Client(this.host, this.ec2client, EC2_LINUX_AMI, this.subnetId, null);
            this.instancesToCleanUp.add(vm2);
        }
        this.cs1 = createComputeState(vm1);
        this.cs2 = createComputeState(vm2);
    } catch (Throwable e) {
        this.host.log("Error starting up services for the test %s", e.getMessage());
        throw new Exception(e);
    }
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) EC2_LINUX_AMI(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.EC2_LINUX_AMI) Arrays(java.util.Arrays) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) TestAWSSetupUtils.deleteVMsUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.deleteVMsUsingEC2Client) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) TestAWSSetupUtils.provisionAWSVMWithEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.provisionAWSVMWithEC2Client) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Duration(java.time.Duration) After(org.junit.After) TestUtils.getExecutor(com.vmware.photon.controller.model.adapters.awsadapter.TestUtils.getExecutor) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) LoadBalancerService(com.vmware.photon.controller.model.resources.LoadBalancerService) HealthCheckConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.HealthCheckConfiguration) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) DeleteLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerRequest) Collection(java.util.Collection) CompletionException(java.util.concurrent.CompletionException) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) AmazonElasticLoadBalancingAsyncClient(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient) List(java.util.List) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.LoadBalancerInstanceRequest.InstanceRequestType) Protocol(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.Protocol) ProvisionLoadBalancerTaskService(com.vmware.photon.controller.model.tasks.ProvisionLoadBalancerTaskService) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) RouteConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.RouteConfiguration) ProvisionLoadBalancerTaskState(com.vmware.photon.controller.model.tasks.ProvisionLoadBalancerTaskService.ProvisionLoadBalancerTaskState) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) HealthCheck(com.amazonaws.services.elasticloadbalancing.model.HealthCheck) ArrayList(java.util.ArrayList) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) ListenerDescription(com.amazonaws.services.elasticloadbalancing.model.ListenerDescription) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) Listener(com.amazonaws.services.elasticloadbalancing.model.Listener) Before(org.junit.Before) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) Assert.assertNull(org.junit.Assert.assertNull) TestContext(com.vmware.xenon.common.test.TestContext) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) TestContext(com.vmware.xenon.common.test.TestContext) CompletionException(java.util.concurrent.CompletionException) CompletionException(java.util.concurrent.CompletionException) Before(org.junit.Before)

Example 60 with AuthCredentialsServiceState

use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.

the class AWSUtils method awsSessionCredentialsToAuthCredentialsState.

/**
 * A helper method to convert an AWS {@link Credentials} object to an
 * {@link AuthCredentialsServiceState} object. This will use the customProperties
 * `SESSION_TOKEN_KEY` and `SESSION_EXPIRATION_TIME_MICROS_KEY` to represent the temporary
 * nature of these credentials.
 */
public static AuthCredentialsServiceState awsSessionCredentialsToAuthCredentialsState(Credentials credentials) {
    AuthCredentialsServiceState authCredentials = new AuthCredentialsServiceState();
    authCredentials.privateKeyId = credentials.getAccessKeyId();
    authCredentials.privateKey = credentials.getSecretAccessKey();
    authCredentials.customProperties = new HashMap<>();
    authCredentials.customProperties.put(SESSION_TOKEN_KEY, credentials.getSessionToken());
    authCredentials.customProperties.put(SESSION_EXPIRATION_TIME_MICROS_KEY, String.valueOf(String.valueOf(credentials.getExpiration().getTime())));
    return authCredentials;
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Aggregations

AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)98 Operation (com.vmware.xenon.common.Operation)33 Before (org.junit.Before)28 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)25 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)19 UriUtils (com.vmware.xenon.common.UriUtils)18 URI (java.net.URI)18 List (java.util.List)18 HashMap (java.util.HashMap)17 CompletionException (java.util.concurrent.CompletionException)16 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)15 Utils (com.vmware.xenon.common.Utils)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 StatelessService (com.vmware.xenon.common.StatelessService)13 TimeUnit (java.util.concurrent.TimeUnit)13 Collections (java.util.Collections)12 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)11 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)10