Search in sources :

Example 76 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project druid by apache.

the class EC2AutoScaler method provision.

@Override
public AutoScalingData provision() {
    try {
        final EC2NodeData workerConfig = envConfig.getNodeData();
        final String userDataBase64;
        if (envConfig.getUserData() == null) {
            userDataBase64 = null;
        } else {
            if (config.getWorkerVersion() == null) {
                userDataBase64 = envConfig.getUserData().getUserDataBase64();
            } else {
                userDataBase64 = envConfig.getUserData().withVersion(config.getWorkerVersion()).getUserDataBase64();
            }
        }
        RunInstancesRequest request = new RunInstancesRequest(workerConfig.getAmiId(), workerConfig.getMinInstances(), workerConfig.getMaxInstances()).withInstanceType(workerConfig.getInstanceType()).withPlacement(new Placement(envConfig.getAvailabilityZone())).withKeyName(workerConfig.getKeyName()).withIamInstanceProfile(workerConfig.getIamProfile() == null ? null : workerConfig.getIamProfile().toIamInstanceProfileSpecification()).withUserData(userDataBase64);
        // leaving it null uses the EC2 default.
        if (workerConfig.getAssociatePublicIpAddress() != null) {
            request.withNetworkInterfaces(new InstanceNetworkInterfaceSpecification().withAssociatePublicIpAddress(workerConfig.getAssociatePublicIpAddress()).withSubnetId(workerConfig.getSubnetId()).withGroups(workerConfig.getSecurityGroupIds()).withDeviceIndex(0));
        } else {
            request.withSecurityGroupIds(workerConfig.getSecurityGroupIds()).withSubnetId(workerConfig.getSubnetId());
        }
        final RunInstancesResult result = amazonEC2Client.runInstances(request);
        final List<String> instanceIds = Lists.transform(result.getReservation().getInstances(), new Function<Instance, String>() {

            @Override
            public String apply(Instance input) {
                return input.getInstanceId();
            }
        });
        log.info("Created instances: %s", instanceIds);
        return new AutoScalingData(Lists.transform(result.getReservation().getInstances(), new Function<Instance, String>() {

            @Override
            public String apply(Instance input) {
                return input.getInstanceId();
            }
        }));
    } catch (Exception e) {
        log.error(e, "Unable to provision any EC2 instances.");
    }
    return null;
}
Also used : AutoScalingData(org.apache.druid.indexing.overlord.autoscaling.AutoScalingData) Instance(com.amazonaws.services.ec2.model.Instance) InstanceNetworkInterfaceSpecification(com.amazonaws.services.ec2.model.InstanceNetworkInterfaceSpecification) Function(com.google.common.base.Function) Placement(com.amazonaws.services.ec2.model.Placement) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) RunInstancesRequest(com.amazonaws.services.ec2.model.RunInstancesRequest)

Example 77 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project druid by apache.

the class EC2AutoScaler method idToIpLookup.

@Override
public List<String> idToIpLookup(List<String> nodeIds) {
    final List<String> retVal = FluentIterable.from(Lists.partition(nodeIds, MAX_AWS_FILTER_VALUES)).transformAndConcat(new Function<List<String>, Iterable<Reservation>>() {

        @Override
        public Iterable<Reservation> apply(List<String> input) {
            return amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("instance-id", input))).getReservations();
        }
    }).transformAndConcat(new Function<Reservation, Iterable<Instance>>() {

        @Override
        public Iterable<Instance> apply(Reservation reservation) {
            return reservation.getInstances();
        }
    }).transform(new Function<Instance, String>() {

        @Override
        public String apply(Instance instance) {
            return instance.getPrivateIpAddress();
        }
    }).toList();
    log.debug("Performing lookup: %s --> %s", nodeIds, retVal);
    return retVal;
}
Also used : Function(com.google.common.base.Function) Reservation(com.amazonaws.services.ec2.model.Reservation) FluentIterable(com.google.common.collect.FluentIterable) Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) List(java.util.List) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 78 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project druid by apache.

the class EC2AutoScaler method terminate.

@Override
public AutoScalingData terminate(List<String> ips) {
    if (ips.isEmpty()) {
        return new AutoScalingData(new ArrayList<>());
    }
    DescribeInstancesResult result = amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("private-ip-address", ips)));
    List<Instance> instances = new ArrayList<>();
    for (Reservation reservation : result.getReservations()) {
        instances.addAll(reservation.getInstances());
    }
    try {
        return terminateWithIds(Lists.transform(instances, new Function<Instance, String>() {

            @Override
            public String apply(Instance input) {
                return input.getInstanceId();
            }
        }));
    } catch (Exception e) {
        log.error(e, "Unable to terminate any instances.");
    }
    return null;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Function(com.google.common.base.Function) Reservation(com.amazonaws.services.ec2.model.Reservation) AutoScalingData(org.apache.druid.indexing.overlord.autoscaling.AutoScalingData) Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 79 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project terra-workspace-manager by DataBiosphere.

the class CreateAiNotebookInstanceStep method createInstanceModel.

private static Instance createInstanceModel(FlightContext flightContext, String projectId, String serviceAccountEmail, String workspaceUserFacingId, String cliServer) {
    Instance instance = new Instance();
    ApiGcpAiNotebookInstanceCreationParameters creationParameters = flightContext.getInputParameters().get(CREATE_NOTEBOOK_PARAMETERS, ApiGcpAiNotebookInstanceCreationParameters.class);
    setFields(creationParameters, serviceAccountEmail, workspaceUserFacingId, cliServer, instance);
    setNetworks(instance, projectId, flightContext.getWorkingMap());
    return instance;
}
Also used : Instance(com.google.api.services.notebooks.v1.model.Instance) ApiGcpAiNotebookInstanceCreationParameters(bio.terra.workspace.generated.model.ApiGcpAiNotebookInstanceCreationParameters)

Example 80 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project terra-workspace-manager by DataBiosphere.

the class RetrieveAiNotebookResourceAttributesStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    final FlightMap workingMap = context.getWorkingMap();
    String projectId = gcpCloudContextService.getRequiredGcpProject(resource.getWorkspaceId());
    InstanceName instanceName = resource.toInstanceName(projectId);
    AIPlatformNotebooksCow notebooksCow = crlService.getAIPlatformNotebooksCow();
    try {
        Instance instance = notebooksCow.instances().get(instanceName).execute();
        Map<String, String> metadata = instance.getMetadata();
        ApiGcpAiNotebookUpdateParameters existingUpdateParameters = new ApiGcpAiNotebookUpdateParameters().metadata(metadata);
        workingMap.put(ControlledResourceKeys.PREVIOUS_UPDATE_PARAMETERS, existingUpdateParameters);
    } catch (GoogleJsonResponseException e) {
        if (HttpStatus.BAD_REQUEST.value() == e.getStatusCode() || HttpStatus.NOT_FOUND.value() == e.getStatusCode()) {
            return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
        }
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    } catch (IOException e) {
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    return StepResult.getStepResultSuccess();
}
Also used : InstanceName(bio.terra.cloudres.google.notebooks.InstanceName) AIPlatformNotebooksCow(bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Instance(com.google.api.services.notebooks.v1.model.Instance) ApiGcpAiNotebookUpdateParameters(bio.terra.workspace.generated.model.ApiGcpAiNotebookUpdateParameters) FlightMap(bio.terra.stairway.FlightMap) IOException(java.io.IOException) StepResult(bio.terra.stairway.StepResult)

Aggregations

Instance (com.amazonaws.services.ec2.model.Instance)185 Reservation (com.amazonaws.services.ec2.model.Reservation)84 ArrayList (java.util.ArrayList)82 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)71 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)48 List (java.util.List)48 Tag (com.amazonaws.services.ec2.model.Tag)41 Test (org.junit.jupiter.api.Test)38 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)36 Map (java.util.Map)36 Collectors (java.util.stream.Collectors)32 HashMap (java.util.HashMap)26 Filter (com.amazonaws.services.ec2.model.Filter)25 Set (java.util.Set)23 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)22 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)20 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)18 InstanceState (com.amazonaws.services.ec2.model.InstanceState)18 Volume (com.amazonaws.services.ec2.model.Volume)18 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)18