Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
Data Flow
Real Time
Streams
Stream Admin Service
Commits
5643c9c0
Commit
5643c9c0
authored
Oct 27, 2021
by
Stephen Nimmo
Browse files
Tests working locally against minikube
parent
7915ff03
Pipeline
#74482
failed with stage
in 2 minutes and 54 seconds
Changes
10
Pipelines
1
Show whitespace changes
Inline
Side-by-side
pom.xml
View file @
5643c9c0
...
...
@@ -48,7 +48,7 @@
<dependency>
<groupId>
io.kubernetes
</groupId>
<artifactId>
client-java
</artifactId>
<version>
1
0
.0.
0
</version>
<version>
1
2
.0.
1
</version>
</dependency>
<!-- Test Dependencies -->
...
...
@@ -105,14 +105,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
11
</source>
<target>
11
</target>
</configuration>
</plugin>
</plugins>
</build>
...
...
src/main/java/org/opengroup/osdu/streaming/service/DeploymentAdminService.java
View file @
5643c9c0
...
...
@@ -2,11 +2,13 @@ package org.opengroup.osdu.streaming.service;
import
org.opengroup.osdu.streaming.model.StreamRecord
;
import
java.util.Optional
;
public
interface
DeploymentAdminService
{
StreamDeploymentStatus
create
StreamDeployment
(
StreamRecord
streamRecord
);
Optional
<
StreamDeploymentStatus
>
find
StreamDeployment
Status
(
StreamRecord
streamRecord
);
StreamDeploymentStatus
get
StreamDeploymentSt
atus
(
String
i
d
);
StreamDeploymentStatus
create
StreamDeployment
(
St
reamRecord
streamRecor
d
);
StreamDeploymentStatus
startStreamDeployment
(
StreamRecord
streamRecord
);
...
...
src/main/java/org/opengroup/osdu/streaming/service/DeploymentAdminServiceImpl.java
View file @
5643c9c0
...
...
@@ -3,7 +3,6 @@ package org.opengroup.osdu.streaming.service;
import
io.kubernetes.client.custom.V1Patch
;
import
io.kubernetes.client.openapi.ApiException
;
import
io.kubernetes.client.openapi.apis.AppsV1Api
;
import
io.kubernetes.client.openapi.apis.CoreV1Api
;
import
io.kubernetes.client.openapi.models.*
;
import
io.kubernetes.client.util.PatchUtils
;
import
org.opengroup.osdu.streaming.exception.StreamAdminException
;
...
...
@@ -12,6 +11,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.context.annotation.RequestScope
;
import
javax.validation.constraints.NotNull
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -22,41 +22,56 @@ public class DeploymentAdminServiceImpl implements DeploymentAdminService {
private
static
final
String
PATCH_REPLICAS
=
"[{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%s}]"
;
private
CoreV1Api
coreV1Api
;
private
AppsV1Api
appsV1Api
;
private
String
namespace
;
private
String
deploymentSuffix
=
"deployment"
;
private
String
selectorMatchLabelKey
=
"run"
;
private
static
final
String
DEPLOYMENT_NAME_SUFFIX
=
"-deployment"
;
private
static
final
String
CONTAINER_NAME_SUFFIX
=
"-container"
;
private
static
final
String
SELECTOR_MATCH_LABEL_KEY
=
"run"
;
public
DeploymentAdminServiceImpl
(
CoreV1Api
coreV1Api
,
AppsV1Api
appsV1Api
,
@Value
(
"${deployment.namespace}"
)
String
namespace
)
{
this
.
coreV1Api
=
coreV1Api
;
this
.
appsV1Api
=
appsV1Api
;
public
DeploymentAdminServiceImpl
(
@Value
(
"${deployment.namespace}"
)
String
namespace
,
AppsV1Api
appsV1Api
)
{
this
.
namespace
=
namespace
;
this
.
appsV1Api
=
appsV1Api
;
}
@Override
public
Optional
<
StreamDeploymentStatus
>
findStreamDeploymentStatus
(
StreamRecord
streamRecord
)
{
this
.
validateStreamRecord
(
streamRecord
);
String
deploymentName
=
this
.
getDeploymentName
(
streamRecord
);
Optional
<
V1Deployment
>
optional
=
findExistingDeployment
(
deploymentName
);
return
optional
.
isPresent
()
?
Optional
.
of
(
new
StreamDeploymentStatus
(
optional
.
get
().
getMetadata
().
getName
(),
optional
.
get
().
getMetadata
().
getNamespace
(),
optional
.
get
().
getSpec
().
getReplicas
()
>
0
?
StreamDeploymentStatus
.
Status
.
RUNNING
:
StreamDeploymentStatus
.
Status
.
STOPPED
,
LocalDateTime
.
now
()))
:
Optional
.
empty
();
}
@Override
public
StreamDeploymentStatus
createStreamDeployment
(
StreamRecord
streamRecord
)
{
this
.
validateStreamRecord
(
streamRecord
);
String
normalizedName
=
this
.
getNormalizedName
(
streamRecord
);
String
deploymentName
=
this
.
getDeploymentName
(
streamRecord
);
if
(
this
.
findExistingDeployment
(
namespace
,
deploymentName
).
isPresent
())
{
throw
new
StreamAdminException
(
"Unable to create "
);
String
containerName
=
this
.
getContainerName
(
streamRecord
);
if
(
this
.
findExistingDeployment
(
deploymentName
).
isPresent
())
{
throw
new
StreamAdminException
(
String
.
format
(
"Unable to create StreamDeployment. A deployment already exists for %s."
,
deploymentName
));
}
V1DeploymentBuilder
v1DeploymentBuilder
=
new
V1DeploymentBuilder
();
v1DeploymentBuilder
.
withNewMetadata
()
.
withName
(
String
.
format
(
"%s-%s"
,
deploymentName
,
this
.
deploymentSuffix
)
)
.
withName
(
deploymentName
)
.
withNamespace
(
this
.
namespace
)
.
endMetadata
()
.
withNewSpec
()
.
withReplicas
(
0
)
.
withNewSelector
()
.
withMatchLabels
(
Map
.
of
(
this
.
se
le
c
to
r
Ma
tchLabelKey
,
deployment
Name
))
.
withMatchLabels
(
Collections
.
sing
leto
n
Ma
p
(
SELECTOR_MATCH_LABEL_KEY
,
normalized
Name
))
.
endSelector
()
.
withNewTemplate
()
.
withNewMetadata
()
.
withLabels
(
Map
.
of
(
this
.
se
le
c
to
r
Ma
tchLabelKey
,
deployment
Name
))
.
withLabels
(
Collections
.
sing
leto
n
Ma
p
(
SELECTOR_MATCH_LABEL_KEY
,
normalized
Name
))
.
endMetadata
()
.
withNewSpec
()
.
withContainers
(
new
V1ContainerBuilder
()
.
withName
(
containerName
)
.
withImage
(
this
.
getImage
(
streamRecord
))
.
withEnv
(
this
.
getEnvVar
(
streamRecord
))
.
build
())
...
...
@@ -72,71 +87,38 @@ public class DeploymentAdminServiceImpl implements DeploymentAdminService {
}
}
private
String
getDeploymentName
(
StreamRecord
streamRecord
)
{
return
streamRecord
.
getKind
();
}
private
String
getImage
(
StreamRecord
streamRecord
)
{
String
image
=
streamRecord
.
getData
().
getDatasetProperties
().
getExtensionProperties
().
getStreamDeployment
().
getImage
();
if
(
Objects
.
isNull
(
image
))
{
throw
new
StreamAdminException
(
"Unable to deploy: ExtensionProperties.StreamDeployment.Image is null"
);
}
return
image
;
}
private
List
<
V1EnvVar
>
getEnvVar
(
StreamRecord
streamRecord
)
{
Map
<
String
,
String
>
envMap
=
streamRecord
.
getData
().
getDatasetProperties
().
getExtensionProperties
().
getStreamDeployment
().
getEnv
();
if
(
envMap
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
return
envMap
.
entrySet
().
stream
().
map
(
entry
->
new
V1EnvVarBuilder
()
.
withName
(
entry
.
getKey
())
.
withValue
(
entry
.
getValue
())
.
build
()
).
collect
(
Collectors
.
toList
());
}
@Override
public
StreamDeploymentStatus
getStreamDeploymentStatus
(
String
id
)
{
Optional
<
V1Deployment
>
optional
=
findExistingDeployment
(
this
.
namespace
,
id
);
return
optional
.
isPresent
()
?
new
StreamDeploymentStatus
(
optional
.
get
().
getMetadata
().
getName
(),
optional
.
get
().
getMetadata
().
getNamespace
(),
optional
.
get
().
getSpec
().
getReplicas
()
>
0
?
StreamDeploymentStatus
.
Status
.
RUNNING
:
StreamDeploymentStatus
.
Status
.
STOPPED
,
LocalDateTime
.
now
())
:
null
;
}
@Override
public
StreamDeploymentStatus
startStreamDeployment
(
StreamRecord
streamRecord
)
{
if
(
this
.
findExistingDeployment
(
this
.
namespace
,
this
.
getDeploymentName
(
streamRecord
)).
isEmpty
())
{
throw
new
StreamAdminException
(
"Unable to start StreamDeployment - Does not exist. "
);
this
.
validateStreamRecord
(
streamRecord
);
String
deploymentName
=
this
.
getDeploymentName
(
streamRecord
);
if
(!
this
.
findExistingDeployment
(
deploymentName
).
isPresent
())
{
throw
new
StreamAdminException
(
String
.
format
(
"Unable to find StreamDeployment for %s"
,
deploymentName
));
}
V1Deployment
v1Deployment
=
this
.
patchReplicas
(
this
.
getD
eploymentName
(
streamRecord
)
,
1
);
V1Deployment
v1Deployment
=
this
.
patchReplicas
(
d
eploymentName
,
1
);
return
new
StreamDeploymentStatus
(
v1Deployment
.
getMetadata
().
getName
(),
v1Deployment
.
getMetadata
().
getNamespace
(),
StreamDeploymentStatus
.
Status
.
RUNNING
,
LocalDateTime
.
now
());
}
@Override
public
StreamDeploymentStatus
stopStreamDeployment
(
StreamRecord
streamRecord
)
{
if
(
this
.
findExistingDeployment
(
this
.
namespace
,
this
.
getDeploymentName
(
streamRecord
)).
isEmpty
())
{
throw
new
StreamAdminException
(
"Unable to stop StreamDeployment - Does not exist. "
);
this
.
validateStreamRecord
(
streamRecord
);
String
deploymentName
=
this
.
getDeploymentName
(
streamRecord
);
if
(!
this
.
findExistingDeployment
(
deploymentName
).
isPresent
())
{
throw
new
StreamAdminException
(
String
.
format
(
"Unable to find StreamDeployment for %s"
,
deploymentName
));
}
V1Deployment
v1Deployment
=
this
.
patchReplicas
(
this
.
getD
eploymentName
(
streamRecord
)
,
0
);
V1Deployment
v1Deployment
=
this
.
patchReplicas
(
d
eploymentName
,
0
);
return
new
StreamDeploymentStatus
(
v1Deployment
.
getMetadata
().
getName
(),
v1Deployment
.
getMetadata
().
getNamespace
(),
StreamDeploymentStatus
.
Status
.
STOPPED
,
LocalDateTime
.
now
());
}
private
V1Deployment
patchReplicas
(
String
deploymentName
,
int
replicas
)
{
String
jsonP
atchStr
=
String
.
format
(
PATCH_REPLICAS
,
1
);
String
p
atchStr
ing
=
String
.
format
(
PATCH_REPLICAS
,
1
);
try
{
V1Deployment
v1Deployment
=
PatchUtils
.
patch
(
return
PatchUtils
.
patch
(
V1Deployment
.
class
,
()
->
appsV1Api
.
patchNamespacedDeploymentCall
(
deploymentName
,
this
.
namespace
,
new
V1Patch
(
jsonP
atchStr
),
new
V1Patch
(
p
atchStr
ing
),
null
,
null
,
null
,
// field-manager is optional
...
...
@@ -144,7 +126,6 @@ public class DeploymentAdminServiceImpl implements DeploymentAdminService {
null
),
V1Patch
.
PATCH_FORMAT_JSON_PATCH
,
appsV1Api
.
getApiClient
());
return
v1Deployment
;
}
catch
(
ApiException
e
)
{
throw
new
StreamAdminException
(
e
);
}
...
...
@@ -152,20 +133,79 @@ public class DeploymentAdminServiceImpl implements DeploymentAdminService {
@Override
public
void
deleteStreamDeployment
(
StreamRecord
streamRecord
)
{
this
.
validateStreamRecord
(
streamRecord
);
try
{
appsV1Api
.
deleteNamespacedDeployment
(
this
.
getDeploymentName
(
streamRecord
),
this
.
namespace
,
null
,
null
,
null
,
null
,
null
,
null
);
String
deploymentName
=
this
.
getDeploymentName
(
streamRecord
);
appsV1Api
.
deleteNamespacedDeployment
(
deploymentName
,
this
.
namespace
,
null
,
null
,
null
,
null
,
null
,
null
);
}
catch
(
ApiException
e
)
{
throw
new
StreamAdminException
(
e
);
}
}
private
Optional
<
V1Deployment
>
findExistingDeployment
(
String
namespace
,
String
n
ame
)
{
private
Optional
<
V1Deployment
>
findExistingDeployment
(
String
deploymentN
ame
)
{
try
{
V1DeploymentList
v1DeploymentList
=
appsV1Api
.
listNamespacedDeployment
(
namespace
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
);
return
v1DeploymentList
.
getItems
().
stream
().
filter
(
v1Deployment
->
v1Deployment
.
getMetadata
().
getName
().
equals
(
n
ame
)).
findFirst
();
V1DeploymentList
v1DeploymentList
=
appsV1Api
.
listNamespacedDeployment
(
this
.
namespace
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
);
return
v1DeploymentList
.
getItems
().
stream
().
filter
(
v1Deployment
->
v1Deployment
.
getMetadata
().
getName
().
equals
(
deploymentN
ame
)).
findFirst
();
}
catch
(
ApiException
e
)
{
throw
new
StreamAdminException
(
e
);
}
}
private
void
validateStreamRecord
(
@NotNull
StreamRecord
streamRecord
)
{
if
(
streamRecord
.
getId
()
==
null
)
{
throw
new
StreamAdminException
(
"StreamRecord.id is null"
);
}
if
(
streamRecord
.
getKind
()
==
null
)
{
throw
new
StreamAdminException
(
"StreamRecord.kind is null"
);
}
if
(
streamRecord
.
getData
()
==
null
)
{
throw
new
StreamAdminException
(
"StreamRecord.data is null"
);
}
if
(
streamRecord
.
getData
().
getDatasetProperties
()
==
null
)
{
throw
new
StreamAdminException
(
"StreamRecord.data.datasetProperties is null"
);
}
if
(
streamRecord
.
getData
().
getDatasetProperties
().
getExtensionProperties
()
==
null
)
{
throw
new
StreamAdminException
(
"StreamRecord.data.datasetProperties.extensionProperties is null"
);
}
if
(
streamRecord
.
getData
().
getDatasetProperties
().
getExtensionProperties
().
getStreamDeployment
()
==
null
)
{
throw
new
StreamAdminException
(
"StreamRecord.data.datasetProperties.extensionProperties.streamDeployment is null"
);
}
if
(
streamRecord
.
getData
().
getDatasetProperties
().
getExtensionProperties
().
getStreamDeployment
().
getImage
()
==
null
)
{
throw
new
StreamAdminException
(
"StreamRecord.data.datasetProperties.extensionProperties.streamDeployment.image is null"
);
}
}
private
String
getNormalizedName
(
StreamRecord
streamRecord
)
{
return
streamRecord
.
getId
().
substring
(
streamRecord
.
getId
().
lastIndexOf
(
':'
)
+
1
);
}
private
String
getDeploymentName
(
StreamRecord
streamRecord
)
{
return
String
.
format
(
"%s%s"
,
this
.
getNormalizedName
(
streamRecord
),
DEPLOYMENT_NAME_SUFFIX
);
}
private
String
getContainerName
(
StreamRecord
streamRecord
)
{
return
String
.
format
(
"%s%s"
,
this
.
getNormalizedName
(
streamRecord
),
CONTAINER_NAME_SUFFIX
);
}
private
String
getImage
(
StreamRecord
streamRecord
)
{
String
image
=
streamRecord
.
getData
().
getDatasetProperties
().
getExtensionProperties
().
getStreamDeployment
().
getImage
();
if
(
Objects
.
isNull
(
image
))
{
throw
new
StreamAdminException
(
"Unable to deploy: ExtensionProperties.StreamDeployment.Image is null"
);
}
return
image
;
}
private
List
<
V1EnvVar
>
getEnvVar
(
StreamRecord
streamRecord
)
{
Map
<
String
,
String
>
envMap
=
streamRecord
.
getData
().
getDatasetProperties
().
getExtensionProperties
().
getStreamDeployment
().
getEnv
();
if
(
envMap
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
return
envMap
.
entrySet
().
stream
().
map
(
entry
->
new
V1EnvVarBuilder
()
.
withName
(
entry
.
getKey
())
.
withValue
(
entry
.
getValue
())
.
build
()
).
collect
(
Collectors
.
toList
());
}
}
src/main/java/org/opengroup/osdu/streaming/service/StreamingAdminServiceImpl.java
View file @
5643c9c0
...
...
@@ -25,7 +25,6 @@ import org.opengroup.osdu.core.common.storage.IStorageService;
import
org.opengroup.osdu.streaming.model.StreamRecord
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.context.annotation.RequestScope
;
...
...
@@ -41,17 +40,20 @@ public class StreamingAdminServiceImpl implements StreamingAdminService {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
StreamingAdminServiceImpl
.
class
);
@Autowired
private
ObjectMapper
objectMapper
;
@Autowired
private
DpsHeaders
headers
;
@Autowired
private
IStorageFactory
storageFactory
;
@Autowired
private
TopicAdminService
topicAdminService
;
private
DeploymentAdminService
deploymentAdminService
;
public
StreamingAdminServiceImpl
(
ObjectMapper
objectMapper
,
DpsHeaders
headers
,
IStorageFactory
storageFactory
,
TopicAdminService
topicAdminService
,
DeploymentAdminService
deploymentAdminService
)
{
this
.
objectMapper
=
objectMapper
;
this
.
headers
=
headers
;
this
.
storageFactory
=
storageFactory
;
this
.
topicAdminService
=
topicAdminService
;
this
.
deploymentAdminService
=
deploymentAdminService
;
}
@Override
public
StreamRecord
getStream
(
String
streamRecordId
)
{
...
...
@@ -108,6 +110,7 @@ public class StreamingAdminServiceImpl implements StreamingAdminService {
// create topic
this
.
topicAdminService
.
createTopic
(
streamRecord
);
this
.
deploymentAdminService
.
createStreamDeployment
(
streamRecord
);
}
catch
(
StorageException
e
)
{
logger
.
error
(
"Got exception: "
+
e
.
getMessage
()
+
"\nFull HTTP Response:"
+
e
.
getHttpResponse
());
}
catch
(
JsonProcessingException
e
)
{
...
...
src/main/java/org/opengroup/osdu/streaming/service/TopicAdminServiceImpl.java
View file @
5643c9c0
...
...
@@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.kafka.config.TopicBuilder
;
import
org.springframework.stereotype.Service
;
import
java.util.
List
;
import
java.util.
Collections
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.concurrent.ExecutionException
;
...
...
@@ -31,7 +31,7 @@ public class TopicAdminServiceImpl implements TopicAdminService {
@Override
public
Optional
<
TopicDescription
>
getTopic
(
StreamRecord
streamRecord
)
{
try
{
Map
<
String
,
KafkaFuture
<
TopicDescription
>>
kafkaFutureMap
=
adminClient
.
describeTopics
(
List
.
of
(
streamRecord
.
getKind
())).
values
();
Map
<
String
,
KafkaFuture
<
TopicDescription
>>
kafkaFutureMap
=
adminClient
.
describeTopics
(
Collections
.
singleton
List
(
streamRecord
.
getKind
())).
values
();
return
kafkaFutureMap
.
containsKey
(
streamRecord
.
getKind
())
?
Optional
.
of
(
kafkaFutureMap
.
get
(
streamRecord
.
getKind
()).
get
())
:
Optional
.
empty
();
}
catch
(
ExecutionException
e
)
{
if
(
e
.
getCause
()
instanceof
UnknownTopicOrPartitionException
)
{
...
...
@@ -56,7 +56,7 @@ public class TopicAdminServiceImpl implements TopicAdminService {
//.partitions(10)
//.replicas(3)
.
build
();
adminClient
.
createTopics
(
List
.
of
(
newTopic
)).
all
().
get
();
adminClient
.
createTopics
(
Collections
.
singleton
List
(
newTopic
)).
all
().
get
();
return
getTopic
(
streamRecord
).
get
();
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
throw
new
StreamAdminException
(
e
);
...
...
@@ -65,7 +65,7 @@ public class TopicAdminServiceImpl implements TopicAdminService {
@Override
public
void
deleteTopic
(
StreamRecord
streamRecord
)
{
adminClient
.
deleteTopics
(
List
.
of
(
streamRecord
.
getKind
()));
adminClient
.
deleteTopics
(
Collections
.
singleton
List
(
streamRecord
.
getKind
()));
}
}
src/main/java/org/opengroup/osdu/streaming/util/KubernetesAdminConfiguration.java
View file @
5643c9c0
...
...
@@ -15,6 +15,7 @@ public class KubernetesAdminConfiguration {
public
KubernetesAdminConfiguration
()
throws
IOException
{
ApiClient
client
=
Config
.
defaultClient
();
io
.
kubernetes
.
client
.
openapi
.
Configuration
.
setDefaultApiClient
(
client
);
client
.
setDebugging
(
true
);
}
@Bean
...
...
src/test/java/org/opengroup/osdu/streaming/service/DeploymentAdminServiceTest.java
View file @
5643c9c0
package
org.opengroup.osdu.streaming.service
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.opengroup.osdu.streaming.model.StreamRecord
;
import
org.junit.jupiter.api.Test
;
import
org.opengroup.osdu.streaming.model.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.Collections
;
import
java.util.Optional
;
import
java.util.UUID
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
@DirtiesContext
@SpringBootTest
public
class
DeploymentAdminServiceTest
{
@Autowired
private
DeploymentAdminService
deploymentAdminService
;
@Test
public
void
createStream
()
{
StreamRecord
streamRecord
=
new
StreamRecord
();
StreamRecord
updatedStreamRecord
=
deploymentAdminService
.
createStream
(
streamRecord
);
assertThat
(
updatedStreamRecord
).
isNull
();
public
void
getStreamDeploymentStatusNotDeployed
()
{
StreamRecord
streamRecord
=
this
.
createRandom
StreamRecord
();
Optional
<
StreamDeploymentStatus
>
streamDeploymentStatus
=
deploymentAdminService
.
findStreamDeploymentStatus
(
streamRecord
);
assertThat
(
streamDeploymentStatus
.
isPresent
()).
isFalse
();
}
@Test
public
void
getStreamInfo
()
{
StreamRecord
streamRecord
=
deploymentAdminService
.
getStreamInfo
(
"test"
);
assertThat
(
streamRecord
).
isNull
();
public
void
createStreamDeploymentAndStartStreamDeploymentAndDelete
()
{
StreamRecord
streamRecord
=
null
;
try
{
streamRecord
=
this
.
createRandomStreamDeployment
();
StreamDeploymentStatus
streamDeploymentStatus
=
deploymentAdminService
.
startStreamDeployment
(
streamRecord
);
assertThat
(
streamDeploymentStatus
).
isNotNull
();
assertThat
(
streamDeploymentStatus
.
getStatus
()).
isEqualTo
(
StreamDeploymentStatus
.
Status
.
RUNNING
);
}
finally
{
deploymentAdminService
.
deleteStreamDeployment
(
streamRecord
);
}
}
@Test
public
void
startStream
()
{
StreamRecord
streamRecord
=
new
StreamRecord
();
deploymentAdminService
.
startStream
(
streamRecord
);
public
void
createStreamDeploymentAndStopStreamDeploymentAndDelete
()
{
StreamRecord
streamRecord
=
null
;
try
{
streamRecord
=
this
.
createRandomStreamDeployment
();
StreamDeploymentStatus
streamDeploymentStatus
=
deploymentAdminService
.
stopStreamDeployment
(
streamRecord
);
assertThat
(
streamDeploymentStatus
).
isNotNull
();
assertThat
(
streamDeploymentStatus
.
getStatus
()).
isEqualTo
(
StreamDeploymentStatus
.
Status
.
STOPPED
);
}
finally
{
deploymentAdminService
.
deleteStreamDeployment
(
streamRecord
);
}
}
@Test
public
void
stopStream
()
{
StreamRecord
streamRecord
=
new
StreamRecord
();
deploymentAdminService
.
stopStream
(
streamRecord
);
private
StreamRecord
createRandomStreamDeployment
()
{
StreamRecord
streamRecord
=
this
.
createRandomStreamRecord
();
StreamDeploymentStatus
streamDeploymentStatus
=
deploymentAdminService
.
createStreamDeployment
(
streamRecord
);
assertThat
(
streamDeploymentStatus
).
isNotNull
();
assertThat
(
streamDeploymentStatus
.
getStatus
()).
isEqualTo
(
StreamDeploymentStatus
.
Status
.
STOPPED
);
return
streamRecord
;
}
@Test
public
void
deleteStream
()
{
private
StreamRecord
createRandomStreamRecord
()
{
StreamRecord
streamRecord
=
new
StreamRecord
();
deploymentAdminService
.
deleteStream
(
streamRecord
);
streamRecord
.
setId
(
this
.
createRandomId
());
streamRecord
.
setKind
(
UUID
.
randomUUID
().
toString
());
StreamDataset
streamDataset
=
new
StreamDataset
();
streamDataset
.
setName
(
UUID
.
randomUUID
().
toString
());
StreamDatasetDatasetProperties
streamDatasetDatasetProperties
=
new
StreamDatasetDatasetProperties
();
StreamDatasetDatasetPropertiesExtensionProperties
streamDatasetDatasetPropertiesExtensionProperties
=
new
StreamDatasetDatasetPropertiesExtensionProperties
();
StreamDatasetDatasetPropertiesExtensionPropertiesStreamDeployment
deployment
=
new
StreamDatasetDatasetPropertiesExtensionPropertiesStreamDeployment
();
deployment
.
setImage
(
"busybox"
);
deployment
.
setEnv
(
Collections
.
singletonMap
(
"ENV1"
,
"ENV1_VALUE"
));
streamDatasetDatasetPropertiesExtensionProperties
.
setStreamDeployment
(
deployment
);
streamDatasetDatasetProperties
.
setExtensionProperties
(
streamDatasetDatasetPropertiesExtensionProperties
);
streamDataset
.
setDatasetProperties
(
streamDatasetDatasetProperties
);
streamRecord
.
setData
(
streamDataset
);
return
streamRecord
;
}
private
String
createRandomId
()
{
return
"test--blah:"
+
UUID
.
randomUUID
();
}
}
src/test/java/org/opengroup/osdu/streaming/service/TopicAdminServiceTest.java
View file @
5643c9c0
...
...
@@ -4,7 +4,6 @@ import org.apache.kafka.clients.admin.AdminClient;
import
org.apache.kafka.clients.admin.AdminClientConfig
;
import
org.apache.kafka.clients.admin.KafkaAdminClient
;
import
org.apache.kafka.clients.admin.TopicDescription
;
import
org.junit.Rule
;
import
org.junit.jupiter.api.Test
;
import
org.opengroup.osdu.streaming.model.StreamRecord
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -54,7 +53,7 @@ public class TopicAdminServiceTest {
assertThat
(
topicDescription
).
isNotNull
();
topicAdminService
.
deleteTopic
(
streamRecord
);
Optional
<
TopicDescription
>
optionalTopicDescription
=
topicAdminService
.
getTopic
(
streamRecord
);
assertThat
(
optionalTopicDescription
.
is
Empty
()).
is
Tru
e
();
assertThat
(
optionalTopicDescription
.
is
Present
()).
is
Fals
e
();
}
@Test
...
...
@@ -74,16 +73,14 @@ public class TopicAdminServiceTest {
public
KafkaAdmin
kafkaAdmin
()
{
Map
<
String
,
Object
>
configs
=
new
HashMap
<>();
configs
.
put
(
AdminClientConfig
.
BOOTSTRAP_SERVERS_CONFIG
,
kafka
.
getBootstrapServers
());
KafkaAdmin
kafkaAdmin
=
new
KafkaAdmin
(
configs
);
return
kafkaAdmin
;
return
new
KafkaAdmin
(
configs
);
}
@Bean
public
AdminClient
adminClient
()
{
Map
<
String
,
Object
>
configs
=
new
HashMap
<>();
configs
.
put
(
AdminClientConfig
.
BOOTSTRAP_SERVERS_CONFIG
,
kafka
.
getBootstrapServers
());
AdminClient
adminClient
=
KafkaAdminClient
.
create
(
configs
);
return
adminClient
;
return
KafkaAdminClient
.
create
(
configs
);
}
}
...
...
src/test/java/org/opengroup/osdu/streaming/
service
/KubeApiTest.java
→
src/test/java/org/opengroup/osdu/streaming/
util
/KubeApiTest
Main
.java
View file @
5643c9c0
package
org.opengroup.osdu.streaming.
service
;
package
org.opengroup.osdu.streaming.
util
;
import
io.kubernetes.client.openapi.ApiClient
;
import
io.kubernetes.client.openapi.ApiException
;
...
...
@@ -8,12 +8,12 @@ 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
java.io.IOException
;
import
java.util.Collections
;
import
java.util.Map
;
public
class
KubeApiTest
{
public
class
KubeApiTest
Main
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
ApiException
{
ApiClient
apiClient
=
Config
.
defaultClient
();
...
...
@@ -31,11 +31,11 @@ public class KubeApiTest {
.
withNewSpec
()
.
withReplicas
(
0
)
.
withNewSelector
()