Commit c12b9474 authored by Ľuboslav Pivarč's avatar Ľuboslav Pivarč
Browse files

fixed extend

parent 699d03f0
package cz.muni.ics.edirex.cbioondemandK8S.service;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import cz.muni.ics.edirex.cbioondemandK8S.Utils;
import cz.muni.ics.edirex.cbioondemandK8S.model.IdentifierCRD;
......@@ -11,13 +14,22 @@ import io.kubernetes.client.apis.AppsV1Api;
import io.kubernetes.client.apis.BatchV1beta1Api;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.apis.CustomObjectsApi;
import io.kubernetes.client.models.*;
import io.kubernetes.client.models.V1DeleteOptions;
import io.kubernetes.client.models.V1Pod;
import io.kubernetes.client.models.V1PodList;
import io.kubernetes.client.models.V1ReplicaSet;
import io.kubernetes.client.models.V1ReplicaSetList;
import io.kubernetes.client.models.V1Service;
import io.kubernetes.client.models.V1ServiceList;
import io.kubernetes.client.models.V1beta1CronJob;
import io.kubernetes.client.models.V1beta1CronJobList;
import io.kubernetes.client.util.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Service
......@@ -29,6 +41,9 @@ public class KubernetesAPI implements KubernetesCalls{
ApiextensionsV1beta1Api extensionsApi;
CustomObjectsApi customObjectsApi;
private static final String PATCH_SCHEDULE = " {\"op\":\"replace\",\"path\":\"/spec/schedule\",\"value\":\"";
private static final String PATCH_SCHEDULE_END = "\"}";
private Logger logger = LoggerFactory.getLogger(KubernetesAPI.class);
public KubernetesAPI() throws IOException {
......@@ -216,8 +231,9 @@ public class KubernetesAPI implements KubernetesCalls{
@Override
public boolean updateCronJob(V1beta1CronJob cronJob, String namespace) {
ArrayList<JsonObject> operationToPatch = getOperations(cronJob);
try {
jobApi.patchNamespacedCronJob(cronJob.getMetadata().getName(), namespace, cronJob, null, null);
jobApi.patchNamespacedCronJob(cronJob.getMetadata().getName(), namespace, operationToPatch, null, null);
return true;
} catch (ApiException e) {
logger.warn("Updating of job failed");
......@@ -226,6 +242,14 @@ public class KubernetesAPI implements KubernetesCalls{
return false;
}
private ArrayList<JsonObject> getOperations(V1beta1CronJob cronJob) {
String scheduleCron = cronJob.getSpec().getSchedule();
JsonElement json = new Gson().fromJson(PATCH_SCHEDULE + scheduleCron + PATCH_SCHEDULE_END, JsonElement.class);
ArrayList<JsonObject> operationToPatch = new ArrayList<>();
operationToPatch.add(json.getAsJsonObject());
return operationToPatch;
}
@Override
public boolean updateIdentifier(IdentifierCRD identifier, String namespace) {
try {
......
......@@ -30,7 +30,7 @@ spec:
spec:
containers:
- name: cbio
image: lpivo/cbioportal:tr5
image: lpivo/cbioportal:tr8
ports:
- name: http
containerPort: 8080
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment