Commit 3cdc5bfe authored by Stephen Nimmo's avatar Stephen Nimmo
Browse files

Incremental update of DeploymentAdminServiceImpl

parent c6a5706d
Pipeline #73959 passed with stage
in 1 minute and 15 seconds
......@@ -17,7 +17,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<!-- Dependency Versions -->
......@@ -105,6 +105,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
......
......@@ -5,52 +5,70 @@ import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Configuration;
import io.kubernetes.client.openapi.apis.AppsV1Api;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.V1Container;
import io.kubernetes.client.openapi.models.V1ContainerBuilder;
import io.kubernetes.client.openapi.models.V1Deployment;
import io.kubernetes.client.openapi.models.V1DeploymentBuilder;
import io.kubernetes.client.util.Config;
import org.opengroup.osdu.streaming.exception.StreamAdminException;
import org.opengroup.osdu.streaming.model.StreamRecord;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.context.annotation.RequestScope;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Service
@RequestScope
public class DeploymentAdminServiceImpl implements DeploymentAdminService {
CoreV1Api coreV1Api;
AppsV1Api appsV1Api;
private CoreV1Api coreV1Api;
private AppsV1Api appsV1Api;
private String namespace;
private String deploymentSuffix = "deployment";
private String selectorMatchLabelKey = "run";
public DeploymentAdminServiceImpl() throws IOException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
coreV1Api = new CoreV1Api();
appsV1Api = new AppsV1Api();
public DeploymentAdminServiceImpl(CoreV1Api coreV1Api, AppsV1Api appsV1Api, @Value("${deployment.namespace}") String namespace) {
this.coreV1Api = coreV1Api;
this.appsV1Api = appsV1Api;
this.namespace = namespace;
}
@Override
public StreamRecord createStream(StreamRecord streamRecord) {
Map<Object, Object> map = parseForNeededFields(streamRecord);
String deploymentName = this.getDeploymentName(streamRecord);
V1Deployment deployment = new V1DeploymentBuilder()
.withNewMetadata()
.withName("TODO")
.withName(String.format("%s-%s", deploymentName, this.deploymentSuffix))
.withNamespace(this.namespace)
.endMetadata()
.withNewSpec()
.withReplicas(0)
.withNewSelector()
.withMatchLabels(Map.of(this.selectorMatchLabelKey, deploymentName))
.endSelector()
.withNewTemplate()
.withNewMetadata()
.withLabels(Map.of(this.selectorMatchLabelKey, deploymentName))
.endMetadata()
.withNewSpec()
.withContainers(new V1ContainerBuilder()
.withImage("TEST")
.build())
.endSpec()
.endTemplate()
.endSpec()
.build();
try {
appsV1Api.createNamespacedDeployment("default", deployment, null, null, null);
V1Deployment namespacedDeployment = appsV1Api.createNamespacedDeployment(namespace, deployment, null, null, null);
} catch (ApiException e) {
e.printStackTrace();
throw new StreamAdminException(e);
}
return null;
return streamRecord;
}
private Map<Object, Object> parseForNeededFields(StreamRecord streamRecord) {
return new HashMap<>();
public String getDeploymentName(StreamRecord streamRecord) {
return streamRecord.getKind();
}
@Override
......
package org.opengroup.osdu.streaming.util;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.apis.AppsV1Api;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
@Configuration
public class KubernetesAdminConfiguration {
public KubernetesAdminConfiguration() throws IOException {
ApiClient client = Config.defaultClient();
io.kubernetes.client.openapi.Configuration.setDefaultApiClient(client);
}
@Bean
public CoreV1Api coreV1Api() {
return new CoreV1Api();
}
@Bean
public AppsV1Api appsV1Api() {
return new AppsV1Api();
}
}
......@@ -7,4 +7,7 @@ spring.main.allow-bean-definition-overriding=true
logging.level.root=INFO
osdu.storage.api=https://blah:1234/api/storage/v2
\ No newline at end of file
osdu.storage.api=https://blah:1234/api/storage/v2
deployment.namespace=osdu-streams
\ No newline at end of file
Supports Markdown
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