2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.cnfm.lcm.bpmn.flows.tasks;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.notFound;
26 import static com.github.tomakehurst.wiremock.client.WireMock.ok;
27 import static com.github.tomakehurst.wiremock.client.WireMock.put;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertThrows;
32 import static org.junit.Assert.assertTrue;
33 import static org.onap.aaiclient.client.aai.AAIVersion.V19;
34 import static org.springframework.http.HttpHeaders.ACCEPT;
35 import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
36 import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE;
38 import java.io.IOException;
39 import java.nio.file.Files;
40 import java.nio.file.Path;
41 import java.nio.file.Paths;
42 import java.time.LocalDateTime;
43 import java.util.List;
45 import java.util.Optional;
46 import java.util.UUID;
47 import org.camunda.bpm.engine.history.HistoricProcessInstance;
48 import org.junit.After;
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.onap.so.cnfm.lcm.bpmn.flows.BaseTest;
52 import org.onap.so.cnfm.lcm.bpmn.flows.GsonProvider;
53 import org.onap.so.cnfm.lcm.bpmn.flows.exceptions.AsRequestProcessingException;
54 import org.onap.so.cnfm.lcm.bpmn.flows.service.JobExecutorService;
55 import org.onap.so.cnfm.lcm.database.beans.AsDeploymentItem;
56 import org.onap.so.cnfm.lcm.database.beans.AsInst;
57 import org.onap.so.cnfm.lcm.database.beans.AsLcmOpOcc;
58 import org.onap.so.cnfm.lcm.database.beans.AsLifecycleParam;
59 import org.onap.so.cnfm.lcm.database.beans.Job;
60 import org.onap.so.cnfm.lcm.database.beans.JobStatusEnum;
61 import org.onap.so.cnfm.lcm.database.beans.OperationStateEnum;
62 import org.onap.so.cnfm.lcm.database.beans.State;
63 import org.onap.so.cnfm.lcm.model.AsInfoModificationRequestDeploymentItems;
64 import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
65 import org.springframework.beans.factory.annotation.Autowired;
66 import org.springframework.beans.factory.annotation.Value;
67 import com.fasterxml.jackson.core.JsonProcessingException;
68 import com.google.gson.Gson;
69 import io.kubernetes.client.custom.IntOrString;
70 import io.kubernetes.client.openapi.models.V1DaemonSet;
71 import io.kubernetes.client.openapi.models.V1DaemonSetList;
72 import io.kubernetes.client.openapi.models.V1DaemonSetSpec;
73 import io.kubernetes.client.openapi.models.V1DaemonSetStatus;
74 import io.kubernetes.client.openapi.models.V1DaemonSetUpdateStrategy;
75 import io.kubernetes.client.openapi.models.V1Deployment;
76 import io.kubernetes.client.openapi.models.V1DeploymentList;
77 import io.kubernetes.client.openapi.models.V1DeploymentSpec;
78 import io.kubernetes.client.openapi.models.V1DeploymentStatus;
79 import io.kubernetes.client.openapi.models.V1Job;
80 import io.kubernetes.client.openapi.models.V1JobCondition;
81 import io.kubernetes.client.openapi.models.V1JobList;
82 import io.kubernetes.client.openapi.models.V1JobStatus;
83 import io.kubernetes.client.openapi.models.V1ObjectMeta;
84 import io.kubernetes.client.openapi.models.V1Pod;
85 import io.kubernetes.client.openapi.models.V1PodCondition;
86 import io.kubernetes.client.openapi.models.V1PodList;
87 import io.kubernetes.client.openapi.models.V1PodStatus;
88 import io.kubernetes.client.openapi.models.V1ReplicaSet;
89 import io.kubernetes.client.openapi.models.V1ReplicaSetList;
90 import io.kubernetes.client.openapi.models.V1ReplicaSetSpec;
91 import io.kubernetes.client.openapi.models.V1ReplicaSetStatus;
92 import io.kubernetes.client.openapi.models.V1RollingUpdateDaemonSet;
93 import io.kubernetes.client.openapi.models.V1RollingUpdateStatefulSetStrategy;
94 import io.kubernetes.client.openapi.models.V1Service;
95 import io.kubernetes.client.openapi.models.V1ServiceList;
96 import io.kubernetes.client.openapi.models.V1StatefulSet;
97 import io.kubernetes.client.openapi.models.V1StatefulSetList;
98 import io.kubernetes.client.openapi.models.V1StatefulSetSpec;
99 import io.kubernetes.client.openapi.models.V1StatefulSetStatus;
100 import io.kubernetes.client.openapi.models.V1StatefulSetUpdateStrategy;
101 import io.kubernetes.client.util.Watch;
104 * @author Waqas Ikram (waqas.ikram@est.tech)
106 public class InstantiateAsTaskTest extends BaseTest {
107 private static final String DEPLOYMENT_ITEM_1_LIFECYCLE_PARAM_1 = ".Values.primary.service.ports.mysql";
108 private static final String DEPLOYMENT_ITEM_1_LIFECYCLE_PARAM_2 = ".Values.primary.service.nodePorts.mysql";
110 private static final String DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_1 = ".Values.service.ports.http";
111 private static final String DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_2 = ".Values.service.ports.https";
112 private static final String DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_3 = ".Values.service.nodePorts";
114 private static final String DEPLOYMENT_ITEM_LIFECYCLE_PARAM_VALUE = "dummy";
115 private static final String RANDOM_UUID = UUID.randomUUID().toString();
116 private static final String SERVICE_INSTANCE_ID = UUID.randomUUID().toString();
117 private static final String AS_INST_ID = SERVICE_INSTANCE_ID;
119 private static final String SERVICE_INSTANCE_ID2 = UUID.randomUUID().toString();
120 private static final String AS_INST_ID2 = SERVICE_INSTANCE_ID2;
121 private static final String ASD_NAME = "InstantiateCnfService";
122 private static final String AS_INST_NAME = ASD_NAME + "-" + System.currentTimeMillis();
123 private static final String ASD_ID = AS_INST_ID;
124 private static final String SRC_TEST_DIR = "src/test/resources";
126 private static final String SDC_GET_RESOURCE_URL = "/sdc/v1/catalog/resources/" + ASD_ID + "/toscaModel";
127 private static final String RESOURCE_ASD_PACKAGE_CSAR_PATH =
128 SRC_TEST_DIR + "/resource-Generatedasdpackage-csar.csar";
130 private static final String AS_DEPLOYMENT_ITEM_1_INST_ID = UUID.randomUUID().toString();
131 private static final String AS_DEPLOYMENT_ITEM_2_INST_ID = UUID.randomUUID().toString();
132 private static final String AS_DEPLOYMENT_ITEM_1_INST_ID2 = UUID.randomUUID().toString();
133 private static final String AS_DEPLOYMENT_ITEM_2_INST_ID2 = UUID.randomUUID().toString();
135 @Value("${cnfm.csar.dir}")
138 @Value("${cnfm.kube-configs-dir}")
139 private String kubeConfigsDir;
142 private JobExecutorService objUnderTest;
145 private MockedHelmClient mockedHelmClient;
148 private MockedKubernetesClientProvider kubernetesClientProvider;
151 private GsonProvider gsonProvider;
155 public void before() {
156 wireMockServer.resetAll();
158 deleteFoldersAndFiles(Paths.get(kubeConfigsDir));
159 Files.createDirectory(Paths.get(kubeConfigsDir));
160 } catch (final IOException ioException) {
161 throw new RuntimeException(
162 "Failed to create/Delete Directory in InstantiateAsTaskTest due to: " + ioException.getMessage());
164 kubernetesClientProvider.setWireMockServer(wireMockServer);
166 gson = gsonProvider.getGson();
170 public void after() {
171 wireMockServer.resetAll();
172 final Path path = Paths.get(dir, AS_INST_ID);
174 deleteFoldersAndFiles(path);
175 deleteFoldersAndFiles(Paths.get(kubeConfigsDir));
176 } catch (final IOException ioException) {
177 logger.debug("Exception occurred while deleting folder and files: {}", ioException.getMessage());
182 public void testInstantiateAsWorkflow_JustUpdateStatus_SuccessfullCase() throws InterruptedException, IOException {
184 mockKubernetesClientEndpoint();
188 wireMockServer.stubFor(get(SDC_GET_RESOURCE_URL)
189 .willReturn(aResponse().withBody(getFileContent(getAbsolutePath(RESOURCE_ASD_PACKAGE_CSAR_PATH)))
190 .withHeader(ACCEPT, APPLICATION_OCTET_STREAM_VALUE)));
192 final AsInst asInst = createAsInst(AS_INST_ID, AS_DEPLOYMENT_ITEM_1_INST_ID, AS_DEPLOYMENT_ITEM_2_INST_ID);
194 databaseServiceProvider.saveAsInst(asInst);
196 createKubeConfigFile(asInst);
198 final String asLcmOpOccId = objUnderTest.runInstantiateAsJob(asInst.getAsInstId(), getInstantiateAsRequest());
200 final Optional<Job> optional = getJobByResourceId(asInst.getAsInstId());
201 assertTrue(optional.isPresent());
202 final Job job = optional.get();
205 assertTrue(waitForProcessInstanceToFinish(job.getProcessInstanceId()));
207 final HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance(job.getProcessInstanceId());
208 assertNotNull(historicProcessInstance);
209 assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState());
211 final Optional<AsInst> asInstOptional = databaseServiceProvider.getAsInst(asInst.getAsInstId());
212 final AsInst actualAsInst = asInstOptional.get();
213 assertEquals(State.INSTANTIATED, actualAsInst.getStatus());
215 final Optional<AsLcmOpOcc> asLcmOpOccOptional = databaseServiceProvider.getAsLcmOpOcc(asLcmOpOccId);
216 assertTrue(asLcmOpOccOptional.isPresent());
217 assertEquals(OperationStateEnum.COMPLETED, asLcmOpOccOptional.get().getOperationState());
219 final List<AsDeploymentItem> actualAsDeploymentItems =
220 databaseServiceProvider.getAsDeploymentItemByAsInstId(actualAsInst.getAsInstId());
221 assertEquals(2, actualAsDeploymentItems.size());
223 actualAsDeploymentItems.forEach(asDeploymentItem -> {
224 assertEquals(State.INSTANTIATED, asDeploymentItem.getStatus());
227 final Map<String, Integer> counter = mockedHelmClient.getCounter();
228 assertEquals(2, counter.size());
229 assertEquals(Integer.valueOf(3), counter.get(asInst.getAsdeploymentItems().get(0).getReleaseName()));
230 assertEquals(Integer.valueOf(3), counter.get(asInst.getAsdeploymentItems().get(1).getReleaseName()));
235 @Test(expected = AsRequestProcessingException.class)
236 public void testInstantiateAsWorkflow_LifecycleParametersMissing_Fail() throws InterruptedException, IOException {
238 wireMockServer.stubFor(get(SDC_GET_RESOURCE_URL)
239 .willReturn(aResponse().withBody(getFileContent(getAbsolutePath(RESOURCE_ASD_PACKAGE_CSAR_PATH)))
240 .withHeader(ACCEPT, APPLICATION_OCTET_STREAM_VALUE)));
242 final AsLifecycleParam lcp3 = new AsLifecycleParam().asLifecycleParam(".Values.extra.missing");
243 final AsInst asInst1 = createAsInst(AS_INST_ID2, AS_DEPLOYMENT_ITEM_1_INST_ID2, AS_DEPLOYMENT_ITEM_2_INST_ID2);
244 asInst1.getAsdeploymentItems().get(0).asLifecycleParams(lcp3);
246 databaseServiceProvider.saveAsInst(asInst1);
248 createKubeConfigFile(asInst1);
250 objUnderTest.runInstantiateAsJob(asInst1.getAsInstId(), getInstantiateAsRequest());
255 public void testInstantiateAsWorkflow_UpdateAsInstState_ExceptionCase() {
257 final AsInst asInst = new AsInst().asInstId(UUID.randomUUID().toString()).name(AS_INST_NAME).asdId(ASD_ID)
258 .asdInvariantId(AS_INST_ID).status(State.NOT_INSTANTIATED).statusUpdatedTime(LocalDateTime.now())
259 .asApplicationName("asApplicationName").asApplicationVersion("asApplicationVersion")
260 .asProvider("asProvider").serviceInstanceId(SERVICE_INSTANCE_ID)
261 .serviceInstanceName("serviceInstanceName").cloudOwner("cloudOwner").cloudRegion("cloudRegion")
262 .tenantId("tenantId");
264 databaseServiceProvider.saveAsInst(asInst);
266 assertThrows(AsRequestProcessingException.class,
267 () -> objUnderTest.runInstantiateAsJob(asInst.getAsInstId(), getInstantiateAsRequest()));
269 final Optional<Job> optional = getJobByResourceId(asInst.getAsInstId());
270 final Job job = optional.get();
272 final Optional<AsInst> asInstOptional = databaseServiceProvider.getAsInst(asInst.getAsInstId());
274 assertEquals(JobStatusEnum.ERROR, job.getStatus());
275 assertEquals(State.FAILED, asInstOptional.get().getStatus());
279 private void mockKubernetesClientEndpoint() {
280 wireMockServer.stubFor(get(urlMatching("/apis/batch/v1/jobs\\?labelSelector.*&watch=true"))
281 .willReturn(aResponse().withBody(getJobResponse()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
282 wireMockServer.stubFor(get(urlMatching("/apis/batch/v1/jobs\\?labelSelector.*&watch=false"))
283 .willReturn(aResponse().withBody(getJobList()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
285 wireMockServer.stubFor(get(urlMatching("/api/v1/pods\\?labelSelector.*&watch=true"))
286 .willReturn(aResponse().withBody(getPodResponse()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
287 wireMockServer.stubFor(get(urlMatching("/api/v1/pods\\?labelSelector.*&watch=false"))
288 .willReturn(aResponse().withBody(getPodList()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
290 wireMockServer.stubFor(get(urlMatching("/api/v1/services\\?labelSelector.*&watch=true"))
291 .willReturn(aResponse().withBody(getServiceResponse()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
292 wireMockServer.stubFor(get(urlMatching("/api/v1/services\\?labelSelector.*&watch=false"))
293 .willReturn(aResponse().withBody(getServiceList()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
295 wireMockServer.stubFor(get(urlMatching("/apis/apps/v1/deployments\\?labelSelector.*&watch=true"))
296 .willReturn(aResponse().withBody(getDeploymentResponse()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
297 wireMockServer.stubFor(get(urlMatching("/apis/apps/v1/deployments\\?labelSelector.*&watch=false"))
298 .willReturn(aResponse().withBody(getDeploymentList()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
300 wireMockServer.stubFor(get(urlMatching("/apis/apps/v1/replicasets\\?labelSelector.*&watch=true"))
301 .willReturn(aResponse().withBody(getReplicaSetResponse()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
302 wireMockServer.stubFor(get(urlMatching("/apis/apps/v1/replicasets\\?labelSelector.*&watch=false"))
303 .willReturn(aResponse().withBody(getReplicaSetList()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
305 wireMockServer.stubFor(get(urlMatching("/apis/apps/v1/daemonsets\\?labelSelector.*&watch=true"))
306 .willReturn(aResponse().withBody(getDaemonSetResponse()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
307 wireMockServer.stubFor(get(urlMatching("/apis/apps/v1/daemonsets\\?labelSelector.*&watch=false"))
308 .willReturn(aResponse().withBody(getDaemonSetList()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
310 wireMockServer.stubFor(get(urlMatching("/apis/apps/v1/statefulsets\\?labelSelector.*&watch=true"))
311 .willReturn(aResponse().withBody(getStatefulSetResponse()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
312 wireMockServer.stubFor(get(urlMatching("/apis/apps/v1/statefulsets\\?labelSelector.*&watch=false"))
313 .willReturn(aResponse().withBody(getStatefulSetList()).withHeader(ACCEPT, APPLICATION_JSON_VALUE)));
316 private String getStatefulSetResponse() {
317 return gson.toJson(new Watch.Response<V1StatefulSet>("ADDED", getStatefulSet()));
320 private String getStatefulSetList() {
321 final V1StatefulSetList v1StatefulSetList = new V1StatefulSetList();
322 v1StatefulSetList.addItemsItem(getStatefulSet());
323 return gson.toJson(v1StatefulSetList);
326 private V1StatefulSet getStatefulSet() {
327 return new V1StatefulSet()
330 .metadata(getV1ObjectMeta())
331 .spec(new V1StatefulSetSpec()
332 .updateStrategy(new V1StatefulSetUpdateStrategy().type("RollingUpdate")
333 .rollingUpdate(new V1RollingUpdateStatefulSetStrategy().partition(Integer.valueOf(0))))
334 .replicas(Integer.valueOf(2)))
335 .status(new V1StatefulSetStatus().updatedReplicas(Integer.valueOf(2))
336 .readyReplicas(Integer.valueOf(2)));
339 private String getDaemonSetResponse() {
340 return gson.toJson(new Watch.Response<V1DaemonSet>("ADDED", getDaemonSet()));
343 private String getDaemonSetList() {
344 final V1DaemonSetList v1DaemonSetList = new V1DaemonSetList();
345 v1DaemonSetList.addItemsItem(getDaemonSet());
346 return gson.toJson(v1DaemonSetList);
349 private V1DaemonSet getDaemonSet() {
350 return new V1DaemonSet().apiVersion("apps/v1").metadata(getV1ObjectMeta())
351 .spec(new V1DaemonSetSpec().updateStrategy(new V1DaemonSetUpdateStrategy().type("RollingUpdate")
352 .rollingUpdate(new V1RollingUpdateDaemonSet().maxUnavailable(new IntOrString("50%")))))
353 .status(new V1DaemonSetStatus().desiredNumberScheduled(Integer.valueOf(2))
354 .numberReady(Integer.valueOf(2)).updatedNumberScheduled(Integer.valueOf(2)));
357 private String getReplicaSetResponse() {
358 return gson.toJson(new Watch.Response<V1ReplicaSet>("ADDED", getReplicaSet()));
361 private String getReplicaSetList() {
362 final V1ReplicaSetList v1ReplicaSetList = new V1ReplicaSetList();
363 v1ReplicaSetList.addItemsItem(getReplicaSet());
364 return gson.toJson(v1ReplicaSetList);
367 private V1ReplicaSet getReplicaSet() {
368 return new V1ReplicaSet().apiVersion("apps/v1").metadata(getV1ObjectMeta())
369 .status(new V1ReplicaSetStatus().readyReplicas(Integer.valueOf(1)))
370 .spec(new V1ReplicaSetSpec().replicas(Integer.valueOf(1)));
373 private V1ObjectMeta getV1ObjectMeta() {
374 return new V1ObjectMeta().name("job-name").namespace("job-namespace").uid(RANDOM_UUID)
375 .resourceVersion(RANDOM_UUID).labels(Map.of("label-key", "label-value"));
378 private String getDeploymentResponse() {
379 return gson.toJson(new Watch.Response<V1Deployment>("ADDED", getDeployment()));
382 private String getDeploymentList() {
383 final V1DeploymentList v1DeploymentList = new V1DeploymentList();
384 v1DeploymentList.addItemsItem(getDeployment());
385 return gson.toJson(v1DeploymentList);
388 private V1Deployment getDeployment() {
389 return new V1Deployment().apiVersion("apps/v1").metadata(getV1ObjectMeta())
390 .status(new V1DeploymentStatus().replicas(Integer.valueOf(1)).availableReplicas(Integer.valueOf(1)))
391 .spec(new V1DeploymentSpec().replicas(Integer.valueOf(1)));
394 private String getServiceResponse() {
395 return gson.toJson(new Watch.Response<V1Service>("ADDED", getService()));
399 private String getServiceList() {
400 final V1ServiceList v1ServiceList = new V1ServiceList();
401 v1ServiceList.addItemsItem(getService());
402 return gson.toJson(v1ServiceList);
405 private V1Service getService() {
406 return new V1Service().apiVersion("v1").metadata(getV1ObjectMeta());
409 private String getPodList() {
410 final V1PodList v1Podlist = new V1PodList();
411 v1Podlist.addItemsItem(getPod());
412 return gson.toJson(v1Podlist);
415 private String getPodResponse() {
416 return gson.toJson(new Watch.Response<V1Pod>("ADDED", getPod()));
419 private V1Pod getPod() {
420 return new V1Pod().apiVersion("v1").metadata(getV1ObjectMeta()).status(new V1PodStatus()
421 .addConditionsItem(new V1PodCondition().type("Ready").status(Boolean.TRUE.toString())));
424 private String getJobResponse() {
425 return gson.toJson(new Watch.Response<V1Job>("ADDED", getJob()));
428 private String getJobList() {
429 final V1JobList v1JobList = new V1JobList();
430 v1JobList.addItemsItem(getJob());
431 return gson.toJson(v1JobList);
434 private V1Job getJob() {
435 return new V1Job().apiVersion("batch/v1").metadata(getV1ObjectMeta()).status(new V1JobStatus()
436 .addConditionsItem(new V1JobCondition().type("Complete").status(Boolean.TRUE.toString())));
439 private void mockAAIEndpoints() throws JsonProcessingException {
440 final String vfModule1EndPoint = "/aai/" + V19 + "/network/generic-vnfs/generic-vnf/" + AS_INST_ID
441 + "/vf-modules/vf-module/" + AS_DEPLOYMENT_ITEM_1_INST_ID;
443 wireMockServer.stubFor(get(urlMatching(vfModule1EndPoint + "\\?resultIndex=0&resultSize=1&format=count"))
444 .willReturn(notFound()));
446 final String vfModule2EndPoint = "/aai/" + V19 + "/network/generic-vnfs/generic-vnf/" + AS_INST_ID
447 + "/vf-modules/vf-module/" + AS_DEPLOYMENT_ITEM_2_INST_ID;
449 wireMockServer.stubFor(get(urlMatching(vfModule2EndPoint + "\\?resultIndex=0&resultSize=1&format=count"))
450 .willReturn(notFound()));
452 wireMockServer.stubFor(put(urlMatching(vfModule1EndPoint)).willReturn(ok()));
453 wireMockServer.stubFor(put(urlMatching(vfModule2EndPoint)).willReturn(ok()));
455 final String k8sResourcesEndpoint = "/aai/" + V19
456 + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner/cloudRegion/tenants/tenant/tenantId/"
457 + "k8s-resources/.*";
458 wireMockServer.stubFor(get(urlMatching(k8sResourcesEndpoint)).willReturn(notFound()));
459 wireMockServer.stubFor(put(urlMatching(k8sResourcesEndpoint)).willReturn(ok()));
461 .stubFor(put(urlMatching(k8sResourcesEndpoint + "/relationship-list/relationship")).willReturn(ok()));
466 private AsInst createAsInst(final String as_inst_id, final String as_deployment_item_1_id,
467 final String as_deployment_item_2_id) {
468 final AsInst asInst = new AsInst().asInstId(as_inst_id).name(AS_INST_NAME).asdId(ASD_ID)
469 .asdInvariantId(as_inst_id).status(State.NOT_INSTANTIATED).statusUpdatedTime(LocalDateTime.now())
470 .asApplicationName("asApplicationName").asApplicationVersion("asApplicationVersion")
471 .asProvider("asProvider").serviceInstanceId(as_inst_id).serviceInstanceName("serviceInstanceName")
472 .cloudOwner("cloudOwner").cloudRegion("cloudRegion").tenantId("tenantId");
474 final String helmFile1 = "Artifacts/Deployment/HELM/sampleapp-db-operator-helm.tgz";
475 final AsLifecycleParam lcp1 = new AsLifecycleParam().asLifecycleParam(DEPLOYMENT_ITEM_1_LIFECYCLE_PARAM_1);
476 final AsLifecycleParam lcp2 = new AsLifecycleParam().asLifecycleParam(DEPLOYMENT_ITEM_1_LIFECYCLE_PARAM_2);
478 final AsDeploymentItem item1 = new AsDeploymentItem().asDeploymentItemInstId(as_deployment_item_1_id)
479 .asInst(asInst).status(State.NOT_INSTANTIATED).name("sampleapp-db").itemId("1").deploymentOrder(1)
480 .artifactFilePath(helmFile1).createTime(LocalDateTime.now()).lastUpdateTime(LocalDateTime.now())
481 .releaseName("testOne").asLifecycleParams(lcp1).asLifecycleParams(lcp2);
483 final String helmFile2 = "Artifacts/Deployment/HELM/sampleapp-services-helm.tgz";
484 final AsLifecycleParam lcpitem2_1 =
485 new AsLifecycleParam().asLifecycleParam(DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_1);
486 final AsLifecycleParam lcpitem2_2 =
487 new AsLifecycleParam().asLifecycleParam(DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_2);
488 final AsLifecycleParam lcpitem2_3 =
489 new AsLifecycleParam().asLifecycleParam(DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_3);
491 final AsDeploymentItem item2 = new AsDeploymentItem().asDeploymentItemInstId(as_deployment_item_2_id)
492 .asInst(asInst).status(State.NOT_INSTANTIATED).name("sampleapp-services").itemId("2").deploymentOrder(2)
493 .artifactFilePath(helmFile2).createTime(LocalDateTime.now()).lastUpdateTime(LocalDateTime.now())
494 .releaseName("testTwo").asLifecycleParams(lcpitem2_1).asLifecycleParams(lcpitem2_2)
495 .asLifecycleParams(lcpitem2_3);
497 asInst.asdeploymentItems(item1);
498 asInst.asdeploymentItems(item2);
502 private InstantiateAsRequest getInstantiateAsRequest() {
503 final AsInfoModificationRequestDeploymentItems lifecycleParams_1 =
504 new AsInfoModificationRequestDeploymentItems().deploymentItemsId("1").lifecycleParameterKeyValues(
505 Map.of(DEPLOYMENT_ITEM_1_LIFECYCLE_PARAM_1, DEPLOYMENT_ITEM_LIFECYCLE_PARAM_VALUE,
506 DEPLOYMENT_ITEM_1_LIFECYCLE_PARAM_2, DEPLOYMENT_ITEM_LIFECYCLE_PARAM_VALUE));
508 final AsInfoModificationRequestDeploymentItems lifecycleParams_2 =
509 new AsInfoModificationRequestDeploymentItems().deploymentItemsId("2").lifecycleParameterKeyValues(
510 Map.of(DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_1, DEPLOYMENT_ITEM_LIFECYCLE_PARAM_VALUE,
511 DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_2, DEPLOYMENT_ITEM_LIFECYCLE_PARAM_VALUE,
512 DEPLOYMENT_ITEM_2_LIFECYCLE_PARAM_3, DEPLOYMENT_ITEM_LIFECYCLE_PARAM_VALUE));
514 return new InstantiateAsRequest().addDeploymentItemsItem(lifecycleParams_1)
515 .addDeploymentItemsItem(lifecycleParams_2);
518 private Path getAbsolutePath(final String path) {
519 final File file = new File(path);
520 return file.toPath();
523 private byte[] getFileContent(final Path path) throws IOException {
524 return Files.readAllBytes(path);