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

Merge branch 'time-rework' into 'v2'

Time refactor

See merge request !10
parents 52753c3c 4203b594
Pipeline #26339 passed with stage
in 17 seconds
......@@ -12,17 +12,24 @@ stages:
before_script:
- echo -n $CI_REGISTRY_PASSWORD | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
.kube-deploy:
script: &kube-deploy
.kube-deploy: &kube-deploy
stage: deploy
<<: *kube-auth
image: registry.gitlab.ics.muni.cz:443/europdx/ci-images/ci:latest
script:
- sed -i "s^__IMAGE__^${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}^" ./k8s/deployment.yml
- sed -i "s^__NAMESPACE__^${NAMESPACE}^" ./k8s/deployment.yml ./k8s/service.yml
- kubectl version
- kubectl get pods -n ${NAMESPACE}
- kubectl apply -f ./k8s
- kubectl rollout status -f ./k8s/deployment.yml
allow_failure: false
.docker-build:
script: &docker-build
.docker-build: &docker-build
stage: build
<<: *docker-login
image: docker:latest
script:
- docker build --pull -t "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}" ./cbioondemandK8S
- docker push "$CI_REGISTRY_IMAGE:${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}"
.docker-build-dry:
......@@ -43,72 +50,42 @@ API Pipeline for MR:
#PRODUCTION
API docker image build:
stage: build
<<: *docker-login
image: docker:latest
script:
*docker-build
<<: *docker-build
only:
refs:
- master
- master
API Kube deploy:
stage: deploy
<<: *kube-auth
image: registry.gitlab.ics.muni.cz:443/europdx/k8s/ci:latest
<<: *kube-deploy
variables:
NAMESPACE: cbio-on-demand
script:
*kube-deploy
only:
refs:
- master
- master
when:
manual
allow_failure: false
#BETA
Beta-API docker image build:
stage: build
<<: *docker-login
image: docker:latest
script:
*docker-build
<<: *docker-build
only:
refs:
- beta
- beta
Beta-API Kube deploy:
stage: deploy
<<: *kube-auth
image: registry.gitlab.ics.muni.cz:443/europdx/k8s/ci:latest
<<: *kube-deploy
variables:
NAMESPACE: cbio-on-demand-beta
script:
*kube-deploy
only:
refs:
- beta
- beta
#DEV
Dev-API docker image build:
stage: build
<<: *docker-login
image: docker:latest
script:
*docker-build
<<: *docker-build
only:
refs:
- dev
- dev
Dev-API Kube deploy:
stage: deploy
<<: *kube-auth
image: registry.gitlab.ics.muni.cz:443/europdx/k8s/ci:latest
<<: *kube-deploy
variables:
NAMESPACE: cbio-on-demand-dev
script:
*kube-deploy
only:
refs:
- dev
- dev
......@@ -20,6 +20,7 @@
</properties>
<dependencies>
<!-- Spring dependencies-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
......@@ -35,7 +36,9 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- ====================================================== -->
<!-- Kubernetes dependencies -->
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
......@@ -54,7 +57,9 @@
<artifactId>cron-utils</artifactId>
<version>9.0.0</version>
</dependency>
</dependencies>
</dependencies>
<build>
<resources>
......
package cz.muni.ics.edirex.cbioondemandK8S;
import cz.muni.ics.edirex.cbioondemandK8S.service.KubernetesCalls;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import java.util.Date;
@SpringBootApplication
@EnableAsync
public class CBioOnDemandK8SApplication {
......@@ -17,19 +12,4 @@ public class CBioOnDemandK8SApplication {
SpringApplication.run(CBioOnDemandK8SApplication.class, args);
System.out.println("Kubernetes is awesome");
}
@Bean
CommandLineRunner test(KubernetesCalls api){
return ( args -> {
int numberOfCalls = 1000;
int waitBetweenCalls = 5;
for (int i = 0; i < numberOfCalls; i++){
long time = new Date().getTime();
int j = api.getReplicaSets("", "cbio-on-demand").size();
time = new Date().getTime() - time;
System.out.println(j + " in " + time);
}
});
}
}
\ No newline at end of file
......@@ -26,6 +26,7 @@ import static com.cronutils.model.field.expression.FieldExpressionFactory.on;
*
*/
@Component
@Deprecated
public class Utils {
public static final long ONE_MINUTE_IN_MILLIS = 60000;
public static final long HOUR = ONE_MINUTE_IN_MILLIS * 60;
......
package cz.muni.ics.edirex.cbioondemandK8S.api;
import cz.muni.ics.edirex.cbioondemandK8S.model.InitialBody;
import cz.muni.ics.edirex.cbioondemandK8S.model.Instance;
import cz.muni.ics.edirex.cbioondemandK8S.model.InstanceExtend;
import cz.muni.ics.edirex.cbioondemandK8S.model.InstanceId;
import cz.muni.ics.edirex.cbioondemandK8S.model.User;
import cz.muni.ics.edirex.cbioondemandK8S.service.CBioOnDemandService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/v2")
public class V2 {
private final String cbiood = "/cbioondemand";
private final String cbioods = "/cbioondemands";
private CBioOnDemandService cBioOnDemand;
public V2(CBioOnDemandService cBioOnDemand) {
this.cBioOnDemand = cBioOnDemand;
}
@PostMapping(cbiood)
public ResponseEntity createCbioOnDemand(@RequestBody InitialBody demand){
Instance instance = cBioOnDemand.create(demand);
if(instance == null)
return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE);
return new ResponseEntity<>(instance , HttpStatus.OK);
}
@GetMapping(cbiood)
public ResponseEntity statusCbioOnDemand(InstanceId id){
Instance instance = cBioOnDemand.status(id.getInstance());
if(instance == null)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(instance, HttpStatus.OK);
}
@DeleteMapping(cbiood)
public ResponseEntity removeCbioOnDemand(InstanceId id){
if(!cBioOnDemand.remove(id.getInstance()))
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(HttpStatus.OK);
}
@PutMapping(cbiood)
public ResponseEntity extendCbioOnDemand(@RequestBody InstanceExtend extend){
Instance instance = cBioOnDemand.extend(extend.getInstance());
if (instance == null)
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity(HttpStatus.OK);
}
@GetMapping(cbioods)
public ResponseEntity listInstancesForUser(User user){
List<Instance> instances = cBioOnDemand.listInstancesForUser(user);
if (instances == null){
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(instances, HttpStatus.OK);
}
}
package cz.muni.ics.edirex.cbioondemandK8S.model.v2;
import cz.muni.ics.edirex.cbioondemandK8S.model.User;
public class CbioDemand {
private User user;
private String datahuList;
private String name;
private String description;
}
package cz.muni.ics.edirex.cbioondemandK8S.model.v2;
import com.google.gson.annotations.SerializedName;
import io.kubernetes.client.models.V1ObjectMeta;
public class IdentifierCRD {
@SerializedName("apiVersion")
private String apiVersion = null;
@SerializedName("kind")
private String kind = null;
@SerializedName("metadata")
private V1ObjectMeta metadata = null;
public String getApiVersion() {
return apiVersion;
}
public void setApiVersion(String apiVersion) {
this.apiVersion = apiVersion;
}
public String getKind() {
return kind;
}
public void setKind(String kind) {
this.kind = kind;
}
public V1ObjectMeta getMetadata() {
return metadata;
}
public void setMetadata(V1ObjectMeta metadata) {
this.metadata = metadata;
}
}
package cz.muni.ics.edirex.cbioondemandK8S.model.v2;
import java.util.Objects;
public class InitialBody {
private User user;
private String sampleIDs;
public InitialBody() {
}
public InitialBody(User user, String sampleIDs) {
this.user = user;
this.sampleIDs = sampleIDs;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getSampleIDs() {
return sampleIDs;
}
public void setSampleIDs(String sampleIDs) {
this.sampleIDs = sampleIDs;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InitialBody that = (InitialBody) o;
return Objects.equals(getUser(), that.getUser()) &&
Objects.equals(sampleIDs, that.sampleIDs);
}
@Override
public int hashCode() {
return Objects.hash(getUser(), sampleIDs);
}
}
package cz.muni.ics.edirex.cbioondemandK8S.model.v2;
public class Instance {
private String id;
private User user;
private long secondsToExpire;
private String url;
private Status status;
public Instance(String id, User user, long secondsToExpire, String url, Status status) {
this.id = id;
this.user = user;
this.secondsToExpire = secondsToExpire;
this.url = url;
this.status = status;
}
public long getSecondsToExpire() {
return secondsToExpire;
}
public void setSecondsToExpire(long secondsToExpire) {
this.secondsToExpire = secondsToExpire;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public void fillReport(long timeToExpire, Status status){
secondsToExpire = timeToExpire;
this.status = status;
}
}
package cz.muni.ics.edirex.cbioondemandK8S.model.v2;
import java.util.Objects;
public class InstanceExtend {
private String id;
private User user;
private long timeToExtend;
public InstanceExtend(String id, User user, int timeToExtend) {
this.id = id;
this.user = user;
this.timeToExtend = timeToExtend;
}
public InstanceExtend() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public long getTimeToExtend() {
return timeToExtend;
}
public void setTimeToExtend(int timeToExtend) {
this.timeToExtend = timeToExtend;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InstanceExtend that = (InstanceExtend) o;
return getTimeToExtend() == that.getTimeToExtend() &&
Objects.equals(getId(), that.getId()) &&
Objects.equals(getUser(), that.getUser());
}
@Override
public int hashCode() {
return Objects.hash(getId(), getUser(), getTimeToExtend());
}
public Instance getInstance(){
return new Instance(id, user, timeToExtend , null , null);
}
}
package cz.muni.ics.edirex.cbioondemandK8S.model.v2;
import java.util.Objects;
public class InstanceId {
private String id;
private User user;
public InstanceId(String id, User user) {
this.id = id;
this.user = user;
}
public InstanceId() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InstanceId that = (InstanceId) o;
return Objects.equals(getId(), that.getId()) &&
Objects.equals(getUser(), that.getUser());
}
@Override
public int hashCode() {
return Objects.hash(getId(), getUser());
}
public Instance getInstance(){
return new Instance(id, user, 0 , null , null);
}
}
package cz.muni.ics.edirex.cbioondemandK8S.model.v2;
public enum Status {
creating,
removing,
notActive,
importing,
failedcreating,
active,
notFound, decide
}
package cz.muni.ics.edirex.cbioondemandK8S.model.v2;
import java.util.Objects;
public class User {
private String userId;
public User() {
}
public User(String userId) {
this.userId = userId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public User id(String id){
setUserId(id);
return this;
}