Search in sources :

Example 1 with BatchConfiguration

use of com.hartwig.platinum.config.BatchConfiguration 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);
    }
}
Also used : IPAllocationPolicy(com.google.api.services.container.v1beta1.model.IPAllocationPolicy) NodePool(com.google.api.services.container.v1beta1.model.NodePool) LoggerFactory(org.slf4j.LoggerFactory) NodeConfig(com.google.api.services.container.v1beta1.model.NodeConfig) Duration.ofSeconds(java.time.Duration.ofSeconds) Container(com.google.api.services.container.v1beta1.Container) JsonKey(com.hartwig.platinum.iam.JsonKey) List.of(java.util.List.of) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Operation(com.google.api.services.container.v1beta1.model.Operation) BatchConfiguration(com.hartwig.platinum.config.BatchConfiguration) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) GcpConfiguration(com.hartwig.platinum.config.GcpConfiguration) TumorNormalPair(com.hartwig.platinum.p5sample.TumorNormalPair) PlatinumConfiguration(com.hartwig.platinum.config.PlatinumConfiguration) Console(com.hartwig.platinum.Console) Logger(org.slf4j.Logger) IOException(java.io.IOException) RetryPolicy(net.jodah.failsafe.RetryPolicy) Cluster(com.google.api.services.container.v1beta1.model.Cluster) Failsafe(net.jodah.failsafe.Failsafe) Create(com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Create) List(java.util.List) Get(com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Get) CreateClusterRequest(com.google.api.services.container.v1beta1.model.CreateClusterRequest) PrivateClusterConfig(com.google.api.services.container.v1beta1.model.PrivateClusterConfig) Duration.ofMinutes(java.time.Duration.ofMinutes) Optional(java.util.Optional) BatchConfiguration(com.hartwig.platinum.config.BatchConfiguration) GcpConfiguration(com.hartwig.platinum.config.GcpConfiguration) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 2 with BatchConfiguration

use of com.hartwig.platinum.config.BatchConfiguration in project platinum by hartwigmedical.

the class KubernetesCluster method submit.

public int submit(final List<SampleArgument> samples) {
    Volume configMapVolume = configMap.asKubernetes();
    Volume secretVolume = serviceAccountSecret.asKubernetes();
    Volume maybeJksVolume = new JksSecret().asKubernetes();
    int numSubmitted = 0;
    for (SampleArgument sample : samples) {
        try {
            PipelineContainer pipelineContainer = new PipelineContainer(sample, runName, new PipelineArguments(configuration.argumentOverrides(), outputBucketName, serviceAccountEmail, runName, configuration), secretVolume.getName(), configMapVolume.getName(), configuration.image());
            if (scheduler.submit(new PipelineJob(runName, sample.id(), configuration.keystorePassword().map(p -> new JksEnabledContainer(pipelineContainer.asKubernetes(), maybeJksVolume, p).asKubernetes()).orElse(pipelineContainer.asKubernetes()), concat(of(configMapVolume, secretVolume), configuration.keystorePassword().map(p -> maybeJksVolume).stream()).collect(toList()), targetNodePool, configuration.gcp().jobTtl().orElse(Duration.ZERO)))) {
                numSubmitted++;
                if (configuration.batch().isPresent()) {
                    BatchConfiguration batchConfiguration = configuration.batch().get();
                    if (numSubmitted % batchConfiguration.size() == 0) {
                        LOGGER.info("Batch of [{}] of [{}] scheduled, waiting [{}] minutes", (numSubmitted / batchConfiguration.size()), (samples.size() / batchConfiguration.size()), batchConfiguration.delay());
                        delay.forMinutes(batchConfiguration.delay());
                    }
                }
            }
        } catch (KubernetesClientException e) {
            LOGGER.warn("Refreshing K8 client as an error was encountered. ", e);
            scheduler.refresh(configuration.cluster().orElse(runName), configuration.gcp());
        }
    }
    return numSubmitted;
}
Also used : KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) PlatinumConfiguration(com.hartwig.platinum.config.PlatinumConfiguration) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Logger(org.slf4j.Logger) Stream.of(java.util.stream.Stream.of) Duration(java.time.Duration) LoggerFactory(org.slf4j.LoggerFactory) Stream.concat(java.util.stream.Stream.concat) BatchConfiguration(com.hartwig.platinum.config.BatchConfiguration) Volume(io.fabric8.kubernetes.api.model.Volume) BatchConfiguration(com.hartwig.platinum.config.BatchConfiguration) Volume(io.fabric8.kubernetes.api.model.Volume) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

BatchConfiguration (com.hartwig.platinum.config.BatchConfiguration)2 PlatinumConfiguration (com.hartwig.platinum.config.PlatinumConfiguration)2 List (java.util.List)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Container (com.google.api.services.container.v1beta1.Container)1 Create (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Create)1 Get (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Get)1 Cluster (com.google.api.services.container.v1beta1.model.Cluster)1 CreateClusterRequest (com.google.api.services.container.v1beta1.model.CreateClusterRequest)1 IPAllocationPolicy (com.google.api.services.container.v1beta1.model.IPAllocationPolicy)1 NodeConfig (com.google.api.services.container.v1beta1.model.NodeConfig)1 NodePool (com.google.api.services.container.v1beta1.model.NodePool)1 Operation (com.google.api.services.container.v1beta1.model.Operation)1 PrivateClusterConfig (com.google.api.services.container.v1beta1.model.PrivateClusterConfig)1 Console (com.hartwig.platinum.Console)1 GcpConfiguration (com.hartwig.platinum.config.GcpConfiguration)1 JsonKey (com.hartwig.platinum.iam.JsonKey)1 TumorNormalPair (com.hartwig.platinum.p5sample.TumorNormalPair)1