use of bio.terra.workspace.service.workspace.exceptions.DuplicateCloudContextException in project terra-workspace-manager by DataBiosphere.
the class WorkspaceDao method createCloudContext.
/**
* Create cloud context
*
* @param workspaceId unique id of the workspace
* @param cloudPlatform cloud platform enum
* @param context serialized cloud context attributes
* @param flightId calling flight id. Used to ensure that we do not delete a good context while
* undoing from trying to create a conflicting context.
*/
// TODO: PF-1238 remove
@Deprecated
@WriteTransaction
public void createCloudContext(UUID workspaceId, CloudPlatform cloudPlatform, String context, String flightId) {
final String platform = cloudPlatform.toSql();
final String sql = "INSERT INTO cloud_context (workspace_id, cloud_platform, context, creating_flight)" + " VALUES (:workspace_id, :cloud_platform, :context::json, :creating_flight)";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("workspace_id", workspaceId.toString()).addValue("cloud_platform", platform).addValue("context", context).addValue("creating_flight", flightId);
try {
jdbcTemplate.update(sql, params);
logger.info("Inserted record for {} cloud context for workspace {}", platform, workspaceId);
} catch (DuplicateKeyException e) {
throw new DuplicateCloudContextException(String.format("Workspace with id %s already has context for %s cloud type", workspaceId, platform), e);
}
}
use of bio.terra.workspace.service.workspace.exceptions.DuplicateCloudContextException in project terra-workspace-manager by DataBiosphere.
the class WorkspaceDao method createCloudContextStart.
/**
* Create cloud context - this is used as part of CreateGcpContextFlightV2 to insert the context
* row at the start of the create context operation.
*/
@WriteTransaction
public void createCloudContextStart(UUID workspaceId, CloudPlatform cloudPlatform, String flightId) {
final String platform = cloudPlatform.toSql();
final String sql = "INSERT INTO cloud_context (workspace_id, cloud_platform, creating_flight)" + " VALUES (:workspace_id, :cloud_platform, :creating_flight)";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("workspace_id", workspaceId.toString()).addValue("cloud_platform", platform).addValue("creating_flight", flightId);
try {
jdbcTemplate.update(sql, params);
logger.info("Inserted record for {} cloud context for workspace {}", platform, workspaceId);
} catch (DuplicateKeyException e) {
throw new DuplicateCloudContextException(String.format("Workspace with id %s already has context for %s cloud type", workspaceId, platform), e);
}
}
use of bio.terra.workspace.service.workspace.exceptions.DuplicateCloudContextException in project terra-workspace-manager by DataBiosphere.
the class StoreGcpContextStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException {
String projectId = flightContext.getWorkingMap().get(GCP_PROJECT_ID, String.class);
// Create the cloud context; throws if another flight already created the context.
Optional<String> creatingFlightId = gcpCloudContextService.getGcpCloudContextFlightId(workspaceId);
if (creatingFlightId.isPresent()) {
if (creatingFlightId.get().equals(flightContext.getFlightId())) {
// This flight has already created the context, meaning this step is being re-run.
return StepResult.getStepResultSuccess();
} else {
throw new DuplicateCloudContextException(String.format("Workspace %s already has a GCP cloud context", workspaceId));
}
}
gcpCloudContextService.createGcpCloudContext(workspaceId, new GcpCloudContext(projectId), flightContext.getFlightId());
return StepResult.getStepResultSuccess();
}
Aggregations