Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes deployment #390

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<junit-params.version>1.1.0</junit-params.version>
<org.projectlombok.version>1.16.20</org.projectlombok.version>
<javax.ws.rs-api.version>2.0.1</javax.ws.rs-api.version>
<kubernetes.version>7.0.0</kubernetes.version>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -456,6 +457,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>${kubernetes.version}</version>
<scope>compile</scope>
</dependency>

</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public enum IaaSType {
AZURE,
CHRONOS,
MARATHON,
QCG;
QCG,
KUBERNETES;
}

@Nullable
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/it/reply/orchestrator/dto/cmdb/CloudService.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class CloudService implements CmdbIdentifiable {

private static final String COMPUTE_SERVICE_PREFIX = EGI_SERVICE_PREFIX + ".vm-management";
private static final String STORAGE_SERVICE_PREFIX = EGI_SERVICE_PREFIX + ".storage-management";
private static final String DEEP_SERVICE_PREFIX = "eu.deep";

public static final String OPENSTACK_COMPUTE_SERVICE = "org.openstack.nova";
public static final String OPENNEBULA_COMPUTE_SERVICE = COMPUTE_SERVICE_PREFIX + ".opennebula";
Expand All @@ -112,7 +113,8 @@ public class CloudService implements CmdbIdentifiable {

public static final String MARATHON_COMPUTE_SERVICE = INDIGO_SERVICE_PREFIX + ".marathon";
public static final String CHRONOS_COMPUTE_SERVICE = INDIGO_SERVICE_PREFIX + ".chronos";
public static final String QCG_COMPUTE_SERVICE = "eu.deep.qcg";
public static final String QCG_COMPUTE_SERVICE = DEEP_SERVICE_PREFIX + ".qcg";
public static final String KUBERNETES_COMPUTE_SERVICE = INDIGO_SERVICE_PREFIX + ".kubernetes";

/**
* Get if the the service is a OpenStack compute service.
Expand Down Expand Up @@ -234,9 +236,14 @@ public boolean isQcgComputeProviderService() {
return QCG_COMPUTE_SERVICE.equals(this.serviceType);
}

/**
* Get if the the service is a Kubernetes compute service.
*
* @return true if the service is a Kubernetes compute service
*/
@JsonIgnore
public boolean isCredentialsRequired() {
return isAwsComputeProviderService() || isAzureComputeProviderService()
|| isOtcComputeProviderService();
public boolean isKubernetesComputeProviderService() {
return KUBERNETES_COMPUTE_SERVICE.equals(this.serviceType);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2015-2019 Santer Reply S.p.A.
* Copyright © 2015-2020 Santer Reply S.p.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import static it.reply.orchestrator.dto.cmdb.CloudService.AWS_COMPUTE_SERVICE;
import static it.reply.orchestrator.dto.cmdb.CloudService.AZURE_COMPUTE_SERVICE;
import static it.reply.orchestrator.dto.cmdb.CloudService.CHRONOS_COMPUTE_SERVICE;
import static it.reply.orchestrator.dto.cmdb.CloudService.KUBERNETES_COMPUTE_SERVICE;
import static it.reply.orchestrator.dto.cmdb.CloudService.MARATHON_COMPUTE_SERVICE;
import static it.reply.orchestrator.dto.cmdb.CloudService.OCCI_COMPUTE_SERVICE;
import static it.reply.orchestrator.dto.cmdb.CloudService.OPENNEBULA_COMPUTE_SERVICE;
Expand Down Expand Up @@ -64,6 +65,9 @@ public JavaType typeFromId(DatabindContext context, String id) {
case QCG_COMPUTE_SERVICE:
subType = QcgService.class;
break;
case KUBERNETES_COMPUTE_SERVICE:
subType = KubernetesService.class;
break;
case OCCI_COMPUTE_SERVICE:
case OPENNEBULA_COMPUTE_SERVICE:
case OPENNEBULA_TOSCA_SERVICE:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright © 2015-2020 Santer Reply S.p.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package it.reply.orchestrator.dto.cmdb;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class KubernetesService extends CloudService {

@Builder(builderMethodName = "kubernetesBuilder")
public KubernetesService(
@NonNull String id,
@NonNull String serviceType,
@NonNull String endpoint,
@NonNull String providerId,
@NonNull CloudServiceType type,
boolean publicService,
@Nullable String region,
@NonNull String hostname,
@Nullable String parentServiceId,
boolean iamEnabled) {
super(id, serviceType, endpoint, providerId, type, publicService, region, hostname,
parentServiceId, iamEnabled);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright © 2015-2020 Santer Reply S.p.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package it.reply.orchestrator.dto.kubernetes;

import lombok.Data;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

@Data
public class KubernetesContainer {

@Nullable
private String image;

@NonNull
private List<KubernetesPortMapping> portMappings = new ArrayList<>();

@NonNull
private Type type;

@Getter
public enum Type {
DOCKER("docker", "tosca.artifacts.Deployment.Image.Container.Docker");

Type(String name, String toscaName) {
this.name = name;
this.toscaName = toscaName;
}

private final String name;

private final String toscaName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package it.reply.orchestrator.dto.kubernetes;

import it.reply.orchestrator.utils.Named;

import lombok.Data;
import lombok.Getter;

import org.checkerframework.checker.nullness.qual.NonNull;

@Data
public class KubernetesPortMapping {

@Getter
public enum Protocol implements Named {

TCP("tcp"),
UDP("udp"),
IGMP("igmp");

private final String name;

Protocol(String name) {
this.name = name;
}

}

@NonNull
private Integer containerPort;

private Integer servicePort;

@NonNull
private Protocol protocol = Protocol.TCP;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright © 2015-2020 Santer Reply S.p.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package it.reply.orchestrator.dto.kubernetes;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import it.reply.orchestrator.utils.ToscaConstants;
import lombok.Data;

@Data
public class KubernetesTask {

public final String getToscaNodeName() {
return ToscaConstants.Nodes.Types.KUBERNETES;
}

private String id;

private List<KubernetesContainer> containers;

private KubernetesContainer container;

private Double cpu;

private Double memory;

private Double replicas;

private Integer instances;

private List<String> volumes = new ArrayList<>();

public Optional<KubernetesContainer> getContainer() {
return Optional.ofNullable(this.container);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2015-2019 Santer Reply S.p.A.
* Copyright © 2015-2020 Santer Reply S.p.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@ public enum DeploymentProvider {
HEAT,
CHRONOS,
MARATHON,
QCG;
QCG,
KUBERNETES;

}
5 changes: 3 additions & 2 deletions src/main/java/it/reply/orchestrator/enums/DeploymentType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2015-2019 Santer Reply S.p.A.
* Copyright © 2015-2020 Santer Reply S.p.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,8 @@ public enum DeploymentType {
CHRONOS,
MARATHON,
TOSCA,
QCG;
QCG,
KUBERNETES;

public static boolean isMesosDeployment(DeploymentType deploymentType) {
return deploymentType == CHRONOS || deploymentType == DeploymentType.MARATHON;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package it.reply.orchestrator.exception.service;


public class KubernetesException extends RuntimeException {

/**
*
*/
private static final long serialVersionUID = 908837224074715831L;

private int status;
private String message;

public KubernetesException(String message) {
super(message);
}

public KubernetesException(String message, Throwable cause) {
super(message, cause);
}

protected KubernetesException(int status, String message) {
this.status = status;
this.message = message;
}

/**
* Gets the status code of the failure, such as 404.
*
* @return status code
*/
public int getStatus() {
return status;
}

@Override
public String getMessage() {
return message + " (status: " + status + ")";
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public CloudProviderEndpoint getCloudProviderEndpoint(CloudService computeServic
iaasType = IaaSType.MARATHON;
} else if (computeService.isQcgComputeProviderService()) {
iaasType = IaaSType.QCG;
} else if (computeService.isKubernetesComputeProviderService()) {
iaasType = IaaSType.KUBERNETES;
} else {
throw new IllegalArgumentException("Unknown Cloud Provider type: " + computeService);
}
Expand Down Expand Up @@ -164,6 +166,8 @@ public DeploymentProvider getDeploymentProvider(DeploymentType deploymentType,
return DeploymentProvider.QCG;
case TOSCA:
return DeploymentProvider.IM;
case KUBERNETES:
return DeploymentProvider.KUBERNETES;
default:
throw new DeploymentException("Unknown DeploymentType: " + deploymentType.toString());
}
Expand Down
Loading