use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container in project pravega by pravega.
the class ZookeeperService method createZookeeperApp.
private App createZookeeperApp() {
App app = new App();
app.setId(this.id);
app.setCpus(cpu);
app.setMem(mem);
app.setInstances(instances);
app.setContainer(new Container());
app.getContainer().setType(CONTAINER_TYPE);
app.getContainer().setDocker(new Docker());
app.getContainer().getDocker().setImage(ZK_IMAGE);
List<HealthCheck> healthCheckList = new ArrayList<>();
final HealthCheck hc = setHealthCheck(300, "TCP", false, 60, 20, 0, ZKSERVICE_ZKPORT);
healthCheckList.add(hc);
app.setHealthChecks(healthCheckList);
return app;
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container in project tests by datanucleus.
the class BasicTest method testInh2.
public void testInh2() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Base base1 = new Base(1, "b1");
Base base2 = new Base(2, "b2");
Base base3 = new Base(3, "b3");
SubBase group1 = new SubBase(4, "b4", "SB1");
SubBase group2 = new SubBase(5, "b5", "SB2");
Container c = new Container(new Base[] { base1, base2, base3, group1, group2 });
pm.makePersistent(c);
tx.commit();
tx.begin();
Collection col = (Collection) pm.newQuery(SubBase.class).execute();
assertTrue(col.size() == 2);
assertTrue(col.contains(group1));
assertTrue(col.contains(group2));
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(Container.class);
clean(SubBase.class);
clean(Base.class);
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container 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.marcnuri.yakc.model.io.k8s.api.core.v1.Container in project platinum by hartwigmedical.
the class KubernetesEngine method create.
private static void create(final Container containerApi, final String parent, final String cluster, final GcpConfiguration gcpConfiguration) {
try {
Cluster newCluster = new Cluster();
newCluster.setName(cluster);
newCluster.setNetwork(gcpConfiguration.networkUrl());
newCluster.setSubnetwork(gcpConfiguration.subnetUrl());
newCluster.setLocations(gcpConfiguration.zones());
NodePool defaultNodePool = new NodePool().setName("default").setInitialNodeCount(2);
final NodeConfig nodeConfig = new NodeConfig().setPreemptible(gcpConfiguration.preemptibleCluster()).setOauthScopes(List.of("https://www.googleapis.com/auth/cloud-platform")).setDiskSizeGb(500);
if (!gcpConfiguration.networkTags().isEmpty()) {
nodeConfig.setTags(gcpConfiguration.networkTags());
}
defaultNodePool.setConfig(nodeConfig);
newCluster.setNodePools(List.of(defaultNodePool));
IPAllocationPolicy ipAllocationPolicy = new IPAllocationPolicy();
if (gcpConfiguration.privateCluster()) {
PrivateClusterConfig privateClusterConfig = new PrivateClusterConfig();
privateClusterConfig.setEnablePrivateEndpoint(true);
privateClusterConfig.setEnablePrivateNodes(true);
privateClusterConfig.setMasterIpv4CidrBlock(gcpConfiguration.masterIpv4CidrBlock());
newCluster.setPrivateCluster(true);
newCluster.setPrivateClusterConfig(privateClusterConfig);
ipAllocationPolicy.setUseIpAliases(true);
}
if (gcpConfiguration.secondaryRangeNamePods().isPresent() && gcpConfiguration.secondaryRangeNameServices().isPresent()) {
ipAllocationPolicy.setClusterSecondaryRangeName(gcpConfiguration.secondaryRangeNamePods().get());
ipAllocationPolicy.setServicesSecondaryRangeName(gcpConfiguration.secondaryRangeNameServices().get());
}
newCluster.setIpAllocationPolicy(ipAllocationPolicy);
CreateClusterRequest createRequest = new CreateClusterRequest();
createRequest.setCluster(newCluster);
Create created = containerApi.projects().locations().clusters().create(parent, createRequest);
Operation execute = created.execute();
LOGGER.info("Creating new kubernetes cluster {} in project {} and region {}, this can take upwards of 5 minutes...", Console.bold(newCluster.getName()), Console.bold(gcpConfiguration.projectOrThrow()), Console.bold(gcpConfiguration.regionOrThrow()));
Failsafe.with(new RetryPolicy<>().withMaxDuration(ofMinutes(15)).withDelay(ofSeconds(15)).withMaxAttempts(-1).handleResult(null).handleResult("RUNNING")).onFailure(objectExecutionCompletedEvent -> LOGGER.info("Waiting on operation, status is [{}]", objectExecutionCompletedEvent.getResult())).get(() -> containerApi.projects().locations().operations().get(String.format("projects/%s/locations/%s/operations/%s", gcpConfiguration.projectOrThrow(), gcpConfiguration.regionOrThrow(), execute.getName())).execute().getStatus());
} catch (Exception e) {
throw new RuntimeException("Failed to create cluster", e);
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container in project pravega by pravega.
the class PravegaControllerService method createPravegaControllerApp.
/**
* To configure the controller app.
*
* @return App instance of marathon app
*/
private App createPravegaControllerApp() {
App app = new App();
app.setId(this.id);
app.setCpus(cpu);
app.setMem(mem);
app.setInstances(instances);
app.setConstraints(setConstraint("hostname", "UNIQUE"));
app.setContainer(new Container());
app.getContainer().setType(CONTAINER_TYPE);
app.getContainer().setDocker(new Docker());
app.getContainer().getDocker().setImage(IMAGE_PATH + "/nautilus/pravega:" + PRAVEGA_VERSION);
String zk = zkUri.getHost() + ":" + ZKSERVICE_ZKPORT;
// set port
app.setPortDefinitions(Arrays.asList(createPortDefinition(CONTROLLER_PORT), createPortDefinition(REST_PORT)));
app.setRequirePorts(true);
List<HealthCheck> healthCheckList = new ArrayList<HealthCheck>();
healthCheckList.add(setHealthCheck(300, "TCP", false, 60, 20, 0, CONTROLLER_PORT));
app.setHealthChecks(healthCheckList);
String controllerSystemProperties = "-Xmx512m" + buildSystemProperty(propertyName("zk.connect.uri"), zk) + buildSystemProperty(propertyName("service.rpc.published.host.nameOrIp"), this.id + ".marathon.mesos") + buildSystemProperty(propertyName("service.rpc.published.port"), String.valueOf(CONTROLLER_PORT)) + buildSystemProperty(propertyName("service.rpc.listener.port"), String.valueOf(CONTROLLER_PORT)) + buildSystemProperty(propertyName("service.rest.listener.port"), String.valueOf(REST_PORT)) + buildSystemProperty("log.level", "DEBUG") + buildSystemProperty("log.dir", "$MESOS_SANDBOX/pravegaLogs") + buildSystemProperty("curator-default-session-timeout", String.valueOf(10 * 1000)) + buildSystemProperty(propertyName("transaction.lease.count.max"), String.valueOf(600 * 1000)) + buildSystemProperty(propertyName("retention.frequency.minutes"), String.valueOf(2));
Map<String, Object> map = new HashMap<>();
map.put("PRAVEGA_CONTROLLER_OPTS", controllerSystemProperties);
app.setEnv(map);
app.setArgs(Arrays.asList("controller"));
return app;
}
Aggregations