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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations