use of com.hartwig.platinum.iam.JsonKey in project platinum by hartwigmedical.
the class KubernetesEngine method findOrCreate.
public KubernetesCluster findOrCreate(final String runName, final List<TumorNormalPair> pairs, final JsonKey jsonKey, final String outputBucketName, final String serviceAccountEmail) {
try {
String clusterName = configuration.cluster().orElse(runName);
GcpConfiguration gcpConfiguration = configuration.gcp();
String parent = String.format("projects/%s/locations/%s", gcpConfiguration.projectOrThrow(), gcpConfiguration.regionOrThrow());
if (find(fullPath(gcpConfiguration.projectOrThrow(), gcpConfiguration.regionOrThrow(), clusterName)).isEmpty()) {
create(containerApi, parent, clusterName, gcpConfiguration);
}
if (!configuration.inCluster()) {
if (!processRunner.execute(of("gcloud", "container", "clusters", "get-credentials", clusterName, "--region", gcpConfiguration.regionOrThrow(), "--project", gcpConfiguration.projectOrThrow()))) {
throw new RuntimeException("Failed to get credentials for cluster");
}
if (!processRunner.execute(of("kubectl", "get", "configmaps"))) {
throw new RuntimeException("Failed to run kubectl command against cluster");
}
LOGGER.info("Connection to cluster {} configured via gcloud and kubectl", Console.bold(clusterName));
}
DefaultKubernetesClient kubernetesClient = new DefaultKubernetesClient();
TargetNodePool targetNodePool = configuration.gcp().nodePoolConfiguration().map(c -> TargetNodePool.fromConfig(c, configuration.batch().map(BatchConfiguration::size).orElse(configuration.samples().isEmpty() ? configuration.sampleIds().size() : configuration.samples().size()))).orElse(TargetNodePool.defaultPool());
if (!targetNodePool.isDefault()) {
new GcloudNodePool(processRunner).create(targetNodePool, serviceAccountEmail, clusterName, gcpConfiguration.projectOrThrow());
}
return new KubernetesCluster(runName, new JobScheduler(kubernetesClient, configuration.retryFailed()), new PipelineServiceAccountSecretVolume(jsonKey, kubernetesClient, "service-account-key"), new PipelineConfigMapVolume(pairs, kubernetesClient, runName), outputBucketName, serviceAccountEmail, configuration, Delay.threadSleep(), targetNodePool);
} catch (Exception e) {
throw new RuntimeException("Failed to create cluster", e);
}
}
use of com.hartwig.platinum.iam.JsonKey in project platinum by hartwigmedical.
the class Platinum method run.
public void run() {
LOGGER.info("Starting platinum run with name {} and input {}", Console.bold(runName), Console.bold(input));
GcpConfiguration gcpConfiguration = configuration.gcp();
PipelineServiceAccount serviceAccount = PipelineServiceAccount.from(iam, resourceManager, runName, gcpConfiguration.projectOrThrow(), configuration);
String serviceAccountEmail = serviceAccount.findOrCreate();
ServiceAccountPrivateKey privateKey = ServiceAccountPrivateKey.from(configuration, iam);
JsonKey jsonKey = privateKey.create(gcpConfiguration.projectOrThrow(), serviceAccountEmail);
List<TumorNormalPair> pairs = DecomposeSamples.apply(configuration.sampleBucket().map(b -> new SampleBucket(storage.get(b)).apply()).orElseGet(configuration::samples));
int submitted = kubernetesEngine.findOrCreate(runName, pairs, jsonKey, OutputBucket.from(storage).findOrCreate(runName, gcpConfiguration.regionOrThrow(), serviceAccountEmail, configuration), serviceAccountEmail).submit(samples(configuration, pairs, runName));
LOGGER.info("Platinum started {} pipelines on GCP", Console.bold(String.valueOf(submitted)));
LOGGER.info("You can monitor their progress with: {}", Console.bold("./platinum status"));
}
Aggregations