Merge "rApp - Hello World SME Invoker"
authorJohn Keeney <john.keeney@est.tech>
Wed, 13 Mar 2024 10:31:58 +0000 (10:31 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Wed, 13 Mar 2024 10:31:58 +0000 (10:31 +0000)
52 files changed:
.gitignore
README.md
participants/participant-impl-dme/src/main/java/org/oransc/participant/dme/handler/AutomationCompositionElementHandler.java
participants/participant-impl-dme/src/main/resources/application.yaml
participants/pom.xml
pom.xml
rapp-manager-acm/src/main/java/com/oransc/rappmanager/acm/service/AcmDeployer.java
rapp-manager-acm/src/test/java/com/oransc/rappmanager/acm/service/AcmDeployerTest.java
rapp-manager-acm/src/test/resources/application.yaml
rapp-manager-acm/src/test/resources/valid-rapp-package.csar [deleted file]
rapp-manager-application/src/main/resources/application.yaml
rapp-manager-application/src/test/java/com/oransc/rappmanager/rest/RappInstanceControllerTest.java
rapp-manager-application/src/test/java/com/oransc/rappmanager/service/DeploymentArtifactsServiceTest.java
rapp-manager-application/src/test/resources/application.yaml [new file with mode: 0644]
rapp-manager-application/src/test/resources/invalid-rapp-package.csar [deleted file]
rapp-manager-application/src/test/resources/valid-rapp-package.csar [deleted file]
rapp-manager-dme/src/test/java/com/oransc/rappmanager/dme/service/DmeAcmInterceptorTest.java
rapp-manager-dme/src/test/java/com/oransc/rappmanager/dme/service/DmeDeployerTest.java
rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar [deleted file]
rapp-manager-dme/src/test/resources/valid-rapp-package.csar [deleted file]
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/configuration/RappsEnvironmentConfiguration.java [new file with mode: 0644]
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/RappServiceEnablerTest.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/ArtifactDefinitionValidatorTest.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/AsdDescriptorValidatorTest.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/FileExistenceValidatorTest.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/RappValidationHandlerTest.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/RappValidationUtilsTest.java
rapp-manager-models/src/test/resources/application.yaml [new file with mode: 0644]
rapp-manager-models/src/test/resources/invalid-rapp-package-empty-asd-yaml.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package-no-asd-yaml.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar [deleted file]
rapp-manager-models/src/test/resources/invalid-rapp-package.csar [deleted file]
rapp-manager-models/src/test/resources/valid-rapp-package.csar [deleted file]
rapp-manager-sme/pom.xml
rapp-manager-sme/src/main/java/com/oransc/rappmanager/sme/service/SmeDeployer.java
rapp-manager-sme/src/test/java/com/oransc/rappmanager/sme/service/SmeDeployerTest.java
rapp-manager-sme/src/test/resources/valid-rapp-package.csar [deleted file]
sample-rapp-generator/rapp-all/Files/Acm/instances/all-instance.json
sample-rapp-generator/rapp-all/Files/Acm/instances/k8s-instance.json
sample-rapp-generator/rapp-all/Files/Sme/invokers/invoker-app1.json
sample-rapp-generator/rapp-all/Files/Sme/invokers/invoker-app2.json
sample-rapp-generator/rapp-hello-world/Files/Acm/instances/k8s-instance.json
scripts/init/generate-test-rapp-packages/generatetestrapppackages.go [new file with mode: 0755]
scripts/init/generate-test-rapp-packages/go.mod [new file with mode: 0644]
scripts/init/generate-test-rapp-packages/go.sum [new file with mode: 0644]
scripts/init/getsmeswagger.go
scripts/init/init-sme-spec.bat [deleted file]
scripts/init/init-sme-spec.sh [deleted file]

index 2cdd29e..a44c9cd 100755 (executable)
@@ -34,3 +34,4 @@ build/
 
 
 openapi/sme/
+*.csar
index d52412c..233c17b 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -5,28 +5,28 @@ rApp manager is an application which lifecycle manages the rApp.
 
 ## Architecture
 
-![Image](docs/images/architecture.png "Rapp Manager Architecture")
+![Image](docs/images/architecture.png "rApp Manager Architecture")
 
 ### rApp Package (<mark>**It is a prototype**</mark>)
 
-![Image](docs/images/rApp-package-1.png "Rapp package")
-![Image](docs/images/rApp-package-2.png "Rapp package")
+![Image](docs/images/rApp-package-1.png "rApp package")
+![Image](docs/images/rApp-package-2.png "rApp package")
 
 ### rApp States
 
-![Image](docs/images/rApp-states.png "Rapp States")
+![Image](docs/images/rApp-states.png "rApp States")
 
 ### rApp Instance States
 
-![Image](docs/images/rApp-instance-states.png "Rapp Instance States")
+![Image](docs/images/rApp-instance-states.png "rApp Instance States")
 
 ### Events responsible for rApp Instance State Transition
 
-![Image](docs/images/rApp-state-events.png "Rapp Manager State Events")
+![Image](docs/images/rApp-state-events.png "rApp Manager State Events")
 
 ### rApp Entity Relationship
 
-![Image](docs/images/rApp-entity-relationship.png "Rapp Entity Relationship")
+![Image](docs/images/rApp-entity-relationship.png "rApp Entity Relationship")
 
 ## Integrations
 
@@ -49,22 +49,22 @@ This integration is based on the ICS as part of O-RAN SC NONRTRIC. It is availab
 
 ### Application Lifecycle
 
-![Image](docs/images/application-lifecycle.png "Rapp Manager Application Lifecycle")
+![Image](docs/images/application-lifecycle.png "rApp Manager Application Lifecycle")
 
 ### rApp Flow
 
-![Image](docs/images/rApp-flow.png "Rapp Flow")
+![Image](docs/images/rApp-flow.png "rApp Flow")
 
 ### rApp Instance Flow
 
-![Image](docs/images/rApp-instance-flow.png "Rapp Instance Flow")
+![Image](docs/images/rApp-instance-flow.png "rApp Instance Flow")
 
 
 ## Maven Build
 
 This build supports Linux and Windows environments.
 
-In case of below error during the build in Windows environment,
+In case of below error during the build in Windows environment:
 
 ```
 [INFO] --- exec-maven-plugin:3.1.0:exec (git submodule update) @ rapp-manager-sme ---
index 71d9aaf..f35cc11 100755 (executable)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2023 Nordix Foundation.
+ *  Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,10 +32,9 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import lombok.AccessLevel;
 import lombok.Getter;
-import lombok.RequiredArgsConstructor;
 import org.apache.http.HttpStatus;
-import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV1;
 import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
@@ -57,21 +57,23 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 @Component
-@RequiredArgsConstructor
-public class AutomationCompositionElementHandler implements AutomationCompositionElementListener {
+public class AutomationCompositionElementHandler extends AcElementListenerV1 {
 
     private static final Coder CODER = new StandardCoder();
 
     private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-    private final ParticipantIntermediaryApi intermediaryApi;
-
     private final AcDmeClient acDmeClient;
 
     // Map of acElement Id and DME services
     @Getter(AccessLevel.PACKAGE)
     private final Map<UUID, ConfigurationEntity> configRequestMap = new ConcurrentHashMap<>();
 
+    public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi, AcDmeClient acDmeClient) {
+        super(intermediaryApi);
+        this.acDmeClient = acDmeClient;
+    }
+
     @Override
     public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws DmeException {
         var configurationEntity = configRequestMap.get(automationCompositionElementId);
index e1f60e1..cfa06aa 100755 (executable)
@@ -22,16 +22,16 @@ participant:
     participantId: 101c62b3-8918-41b9-a747-d21eb79c6c08
     clampAutomationCompositionTopics:
       topicSources:
-        - topic: POLICY-ACRUNTIME-PARTICIPANT
+        - topic: policy-acruntime-participant
           servers:
-            - ${topicServer:localhost}
-          topicCommInfrastructure: dmaap
+            - ${topicServer:kafka.default.svc.cluster.local:9092}
+          topicCommInfrastructure: NOOP
           fetchTimeout: 15000
       topicSinks:
-        - topic: POLICY-ACRUNTIME-PARTICIPANT
+        - topic: policy-acruntime-participant
           servers:
-            - ${topicServer:localhost}
-          topicCommInfrastructure: dmaap
+            - ${topicServer:kafka.default.svc.cluster.local:9092}
+          topicCommInfrastructure: NOOP
     participantSupportedElementTypes:
       -
         typeName: org.onap.policy.clamp.acm.DMEAutomationCompositionElement
index 5d3a73a..08bb794 100755 (executable)
@@ -54,7 +54,7 @@
         <openapi.maven.version>7.3.0</openapi.maven.version>
         <docker-maven-plugin>0.43.4</docker-maven-plugin>
         <jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
-        <onap.acm.models.version>7.1.0</onap.acm.models.version>
+        <onap.acm.models.version>7.1.1</onap.acm.models.version>
         <openapi.jackson.databind.nullable.version>0.2.6</openapi.jackson.databind.nullable.version>
     </properties>
     <build>
diff --git a/pom.xml b/pom.xml
index b772daa..b6733ad 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
@@ -52,7 +52,7 @@
         <openapi.maven.version>7.3.0</openapi.maven.version>
         <docker-maven-plugin>0.43.4</docker-maven-plugin>
         <jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
-        <onap.acm.models.version>7.1.0</onap.acm.models.version>
+        <onap.acm.models.version>7.1.1</onap.acm.models.version>
         <openapi.jackson.databind.nullable.version>0.2.6</openapi.jackson.databind.nullable.version>
         <spring.statemachine.version>4.0.0</spring.statemachine.version>
         <spring.context.version>6.1.3</spring.context.version>
@@ -63,6 +63,7 @@
         <slf4j.version>2.0.12</slf4j.version>
         <apache.httpcore.version>4.4.16</apache.httpcore.version>
         <exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
+        <copy-resources-maven-plugin.version>3.3.1</copy-resources-maven-plugin.version>
         <apache.compress.version>1.25.0</apache.compress.version>
     </properties>
     <build>
                     <skipTests>false</skipTests>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>exec-maven-plugin</artifactId>
+                <version>${exec-maven-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <id>generate-test-csar-packages</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>exec</goal>
+                        </goals>
+                        <configuration>
+                            <workingDirectory>
+                                scripts/init/generate-test-rapp-packages
+                            </workingDirectory>
+                            <executable>
+                                go
+                            </executable>
+                            <arguments>
+                                <argument>run</argument>
+                                <argument>generatetestrapppackages.go</argument>
+                            </arguments>
+                        </configuration>
+                        <inherited>false</inherited>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
index c1a035c..dce7be8 100755 (executable)
@@ -133,8 +133,7 @@ public class AcmDeployer implements RappDeployer {
     @Override
     public boolean deployRappInstance(Rapp rapp, RappInstance rappInstance) {
         try {
-            String instantiationPayload =
-                    rappCsarConfigurationHandler.getInstantiationPayload(rapp, rappInstance.getAcm(),
+            String instantiationPayload = rappCsarConfigurationHandler.getInstantiationPayload(rapp, rappInstance,
                             rapp.getCompositionId());
             AutomationComposition automationComposition =
                     gson.fromJson(instantiationPayload, AutomationComposition.class);
index 30c77a1..5f6b509 100755 (executable)
@@ -37,6 +37,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.acm.configuration.ACMConfiguration;
 import com.oransc.rappmanager.dme.service.DmeAcmInterceptor;
 import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappEvent;
@@ -78,8 +79,8 @@ import org.springframework.web.client.RestTemplate;
 
 @SpringBootTest(
         classes = {BeanTestConfiguration.class, ACMConfiguration.class, AcmDeployer.class, DmeAcmInterceptor.class,
-                RappCsarConfigurationHandler.class, RappCacheService.class, RappInstanceStateMachineConfig.class,
-                RappInstanceStateMachine.class})
+                RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class, RappCacheService.class,
+                RappInstanceStateMachineConfig.class, RappInstanceStateMachine.class})
 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
 @AutoConfigureMockMvc
 class AcmDeployerTest {
index 2fdadf4..2df8f66 100755 (executable)
@@ -1,7 +1,10 @@
 rappmanager:
   acm:
-    baseurl: http://10.101.3.22:30442/onap/policy/clamp/acm/v2/
+    baseurl: http://localhost:30442/onap/policy/clamp/acm/v2/
     username: runtimeUser
     password: zb!XztG34
     maxRetries: 3
-    retryInterval: 2 #seconds
\ No newline at end of file
+    retryInterval: 2 #seconds
+  rapps:
+    env:
+      smeDiscoveryEndpoint: http://localhost:53012/service-apis/v1/allServiceAPIs
\ No newline at end of file
diff --git a/rapp-manager-acm/src/test/resources/valid-rapp-package.csar b/rapp-manager-acm/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index b6318e8..0000000
Binary files a/rapp-manager-acm/src/test/resources/valid-rapp-package.csar and /dev/null differ
index 0097f86..2a8489a 100755 (executable)
@@ -1,20 +1,24 @@
 rappmanager:
   csarlocation: src/test/resources/csar
   acm:
-    baseurl: http://10.101.2.41:30442/onap/policy/clamp/acm/v2/
+    baseurl: http://localhost:30442/onap/policy/clamp/acm/v2/
     username: runtimeUser
     password: zb!XztG34
     maxRetries: 10
     retryInterval: 2 #seconds
   sme:
-    baseurl: http://localhost:56571 #http://10.101.3.22:61761
+    baseurl: http://localhost:56571
     providerBasePath: /api-provider-management/v1/
     invokerBasePath: /api-invoker-management/v1/
     publishApiBasePath: /published-apis/v1/
     maxRetries: 3
     retryInterval: 2 #seconds
   dme:
-    baseurl: http://localhost:63475 #http://10.101.3.22:61761
+    baseurl: http://localhost:63475
+
+  rapps:
+    env:
+      smeDiscoveryEndpoint: http://localhost:53012/service-apis/v1/allServiceAPIs
 
 spring:
   jackson:
index 5848fee..931901e 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START======================================================================
- * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
  * ===============================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,13 +27,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.acm.service.AcmDeployer;
 import com.oransc.rappmanager.dme.service.DmeDeployer;
-import com.oransc.rappmanager.models.rappinstance.DeployOrder;
+import com.oransc.rappmanager.models.cache.RappCacheService;
 import com.oransc.rappmanager.models.rapp.Rapp;
+import com.oransc.rappmanager.models.rapp.RappState;
+import com.oransc.rappmanager.models.rappinstance.DeployOrder;
 import com.oransc.rappmanager.models.rappinstance.RappInstance;
 import com.oransc.rappmanager.models.rappinstance.RappInstanceDeployOrder;
 import com.oransc.rappmanager.models.rappinstance.RappInstanceState;
-import com.oransc.rappmanager.models.rapp.RappState;
-import com.oransc.rappmanager.models.cache.RappCacheService;
 import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine;
 import com.oransc.rappmanager.sme.service.SmeDeployer;
 import com.oransc.rappmanager.sme.service.SmeLifecycleManager;
@@ -76,7 +76,6 @@ class RappInstanceControllerTest {
 
     private final String validRappFile = "valid-rapp-package.csar";
 
-    private final String invalidRappFile = "invalid-rapp-package.csar";
     private final String validCsarFileLocation = "src/test/resources/";
 
     private final ObjectMapper objectMapper = new ObjectMapper();
index 5de2050..b8364d9 100755 (executable)
@@ -93,7 +93,7 @@ class DeploymentArtifactsServiceTest {
 
     @Test
     void testChartUploadNoArtifacts() {
-        String invalidRappFile = "invalid-rapp-package.csar";
+        String invalidRappFile = "valid-rapp-package-no-artifacts.csar";
         Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(invalidRappFile)
                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
         rapp.setAsdMetadata(rappCsarConfigurationHandler.getAsdMetadata(rapp));
diff --git a/rapp-manager-application/src/test/resources/application.yaml b/rapp-manager-application/src/test/resources/application.yaml
new file mode 100644 (file)
index 0000000..2a8489a
--- /dev/null
@@ -0,0 +1,39 @@
+rappmanager:
+  csarlocation: src/test/resources/csar
+  acm:
+    baseurl: http://localhost:30442/onap/policy/clamp/acm/v2/
+    username: runtimeUser
+    password: zb!XztG34
+    maxRetries: 10
+    retryInterval: 2 #seconds
+  sme:
+    baseurl: http://localhost:56571
+    providerBasePath: /api-provider-management/v1/
+    invokerBasePath: /api-invoker-management/v1/
+    publishApiBasePath: /published-apis/v1/
+    maxRetries: 3
+    retryInterval: 2 #seconds
+  dme:
+    baseurl: http://localhost:63475
+
+  rapps:
+    env:
+      smeDiscoveryEndpoint: http://localhost:53012/service-apis/v1/allServiceAPIs
+
+spring:
+  jackson:
+    default-property-inclusion: non_null
+
+logging:
+  level:
+    root: INFO
+    com.oransc: DEBUG
+    org.apache.http: DEBUG
+    httpclient.wire: DEBUG
+    org.springframework.web.client.RestTemplate: TRACE
+
+management:
+  endpoints:
+    web:
+      exposure:
+        include: "*"
diff --git a/rapp-manager-application/src/test/resources/invalid-rapp-package.csar b/rapp-manager-application/src/test/resources/invalid-rapp-package.csar
deleted file mode 100755 (executable)
index 81d084b..0000000
Binary files a/rapp-manager-application/src/test/resources/invalid-rapp-package.csar and /dev/null differ
diff --git a/rapp-manager-application/src/test/resources/valid-rapp-package.csar b/rapp-manager-application/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index 1dddd4a..0000000
Binary files a/rapp-manager-application/src/test/resources/valid-rapp-package.csar and /dev/null differ
index fb51f29..005afcc 100755 (executable)
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonParser;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappDmeResourceBuilder;
@@ -48,7 +49,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
-@SpringBootTest(classes = {ObjectMapper.class, RappCsarConfigurationHandler.class, DmeAcmInterceptor.class})
+@SpringBootTest(classes = {ObjectMapper.class, RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class,
+        DmeAcmInterceptor.class})
 class DmeAcmInterceptorTest {
 
     @Autowired
index acbf697..7961cc2 100755 (executable)
@@ -31,6 +31,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.dme.configuration.DmeConfiguration;
 import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappDmeResourceBuilder;
@@ -65,8 +66,8 @@ import org.springframework.test.web.client.MockRestServiceServer;
 import org.springframework.web.client.RestTemplate;
 
 @SpringBootTest(classes = {DmeConfiguration.class, DmeDeployer.class, BeanTestConfiguration.class,
-        RappCsarConfigurationHandler.class, RappCacheService.class, RappInstanceStateMachineConfig.class,
-        RappInstanceStateMachine.class})
+        RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class, RappCacheService.class,
+        RappInstanceStateMachineConfig.class, RappInstanceStateMachine.class})
 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
 @AutoConfigureMockMvc
 class DmeDeployerTest {
diff --git a/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar b/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar
deleted file mode 100755 (executable)
index 36dd2e9..0000000
Binary files a/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar and /dev/null differ
diff --git a/rapp-manager-dme/src/test/resources/valid-rapp-package.csar b/rapp-manager-dme/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index 45a40e4..0000000
Binary files a/rapp-manager-dme/src/test/resources/valid-rapp-package.csar and /dev/null differ
diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/configuration/RappsEnvironmentConfiguration.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/configuration/RappsEnvironmentConfiguration.java
new file mode 100644 (file)
index 0000000..941556e
--- /dev/null
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
+ * ===============================================================================================
+ * 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.
+ * ============LICENSE_END========================================================================
+ */
+
+package com.oransc.rappmanager.models.configuration;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConfigurationProperties(prefix = "rappmanager.rapps.env")
+@Data
+public class RappsEnvironmentConfiguration {
+
+    String smeDiscoveryEndpoint;
+}
\ No newline at end of file
index f71315f..cb071b9 100755 (executable)
@@ -26,9 +26,10 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.Gson;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappResources;
-import com.oransc.rappmanager.models.rappinstance.RappACMInstance;
+import com.oransc.rappmanager.models.rappinstance.RappInstance;
 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -59,15 +60,19 @@ public class RappCsarConfigurationHandler {
     Logger logger = LoggerFactory.getLogger(RappCsarConfigurationHandler.class);
 
     private final ObjectMapper objectMapper;
+    private final RappsEnvironmentConfiguration rappsEnvironmentConfiguration;
 
     public Path getRappPackageLocation(String csarLocation, String rappId, String fileName) {
         return Path.of(csarLocation, rappId, fileName);
     }
 
-    public String getInstantiationPayload(Rapp rapp, RappACMInstance rappACMInstance, UUID compositionId) {
-        return getPayload(rapp,
-                getResourceUri(RappCsarPathProvider.ACM_INSTANCES_LOCATION, rappACMInstance.getInstance())).replaceAll(
-                "DO_NOT_CHANGE_THIS_COMPOSITION_ID", String.valueOf(compositionId));
+    public String getInstantiationPayload(Rapp rapp, RappInstance rappInstance, UUID compositionId) {
+        return getPayload(rapp, getResourceUri(RappCsarPathProvider.ACM_INSTANCES_LOCATION,
+                rappInstance.getAcm().getInstance())).replace("DO_NOT_CHANGE_THIS_COMPOSITION_ID",
+                        String.valueOf(compositionId))
+                       .replace("DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID", String.valueOf(rappInstance.getRappInstanceId()))
+                       .replace("DO_NOT_CHANGE_THIS_SME_DISCOVERY_ENDPOINT",
+                               rappsEnvironmentConfiguration.getSmeDiscoveryEndpoint());
     }
 
     public ByteArrayResource getArtifactPayload(Rapp rapp, String location) {
@@ -139,8 +144,6 @@ public class RappCsarConfigurationHandler {
     }
 
 
-
-
     public String getSmeProviderDomainPayload(Rapp rapp, RappSMEInstance rappSMEInstance) {
         return getPayload(rapp, getResourceUri(RappCsarPathProvider.SME_PROVIDER_FUNCS_LOCATION,
                 rappSMEInstance.getProviderFunction()));
@@ -151,9 +154,10 @@ public class RappCsarConfigurationHandler {
                 getResourceUri(RappCsarPathProvider.SME_SERVICE_APIS_LOCATION, rappSMEInstance.getServiceApis()));
     }
 
-    public String getSmeInvokerPayload(Rapp rapp, RappSMEInstance rappSMEInstance) {
-        return getPayload(rapp,
-                getResourceUri(RappCsarPathProvider.SME_INVOKERS_LOCATION, rappSMEInstance.getInvokers()));
+    public String getSmeInvokerPayload(Rapp rapp, RappInstance rappInstance) {
+        return getPayload(rapp, getResourceUri(RappCsarPathProvider.SME_INVOKERS_LOCATION,
+                rappInstance.getSme().getInvokers())).replace("DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID",
+                String.valueOf(rappInstance.getRappInstanceId()));
     }
 
     public String getAcmCompositionPayload(Rapp rapp) {
index 69ddc9b..4c0a63c 100755 (executable)
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappResources;
@@ -36,7 +37,8 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ContextConfiguration;
 
 @SpringBootTest
-@ContextConfiguration(classes = {ObjectMapper.class, RappCsarConfigurationHandler.class})
+@ContextConfiguration(
+        classes = {ObjectMapper.class, RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class})
 class RappServiceEnablerTest {
 
     @Autowired
index 9f1893b..f1d3044 100755 (executable)
@@ -29,12 +29,15 @@ import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.JsonSyntaxException;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappResources;
 import com.oransc.rappmanager.models.rappinstance.RappACMInstance;
 import com.oransc.rappmanager.models.rappinstance.RappDMEInstance;
+import com.oransc.rappmanager.models.rappinstance.RappInstance;
 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -42,21 +45,30 @@ import java.io.IOException;
 import java.util.Set;
 import java.util.UUID;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.mock.mockito.SpyBean;
 import org.springframework.test.context.ContextConfiguration;
 
 @SpringBootTest
-@ContextConfiguration(classes = {ObjectMapper.class, RappCsarConfigurationHandler.class})
+@EnableConfigurationProperties
+@ContextConfiguration(
+        classes = {ObjectMapper.class, RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class})
 class RappCsarConfigurationHandlerTest {
 
     @SpyBean
     RappCsarConfigurationHandler rappCsarConfigurationHandler;
+    @Autowired
+    RappsEnvironmentConfiguration rappsEnvironmentConfiguration;
+    @Autowired
+    ObjectMapper objectMapper;
 
     String validCsarFileLocation = "src/test/resources/";
 
@@ -67,14 +79,27 @@ class RappCsarConfigurationHandlerTest {
     private final String invalidRappEmptyAsdFile = "invalid-rapp-package-empty-asd-yaml.csar";
 
     @Test
-    void testCsarInstantiationPayload() throws JSONException {
+    void testCsarInstantiationPayload() throws JSONException, JsonProcessingException {
         Rapp rapp = Rapp.builder().name("").packageName(validRappFile).packageLocation(validCsarFileLocation).build();
         UUID compositionId = UUID.randomUUID();
-        RappACMInstance rappACMInstance = new RappACMInstance();
-        rappACMInstance.setInstance("kserve-instance");
-        JSONObject jsonObject = new JSONObject(
-                rappCsarConfigurationHandler.getInstantiationPayload(rapp, rappACMInstance, compositionId));
-        assertEquals(jsonObject.get("compositionId"), String.valueOf(compositionId));
+        RappInstance rappInstance = new RappInstance();
+        RappACMInstance rappKserveACMInstance = new RappACMInstance();
+        rappKserveACMInstance.setInstance("kserve-instance");
+        rappInstance.setAcm(rappKserveACMInstance);
+        JSONObject kserveInstanceJsonObject =
+                new JSONObject(rappCsarConfigurationHandler.getInstantiationPayload(rapp, rappInstance, compositionId));
+        assertEquals(kserveInstanceJsonObject.get("compositionId"), String.valueOf(compositionId));
+        RappACMInstance rappK8sACMInstance = new RappACMInstance();
+        rappK8sACMInstance.setInstance("k8s-instance");
+        rappInstance.setAcm(rappK8sACMInstance);
+        JsonNode jsonNode = objectMapper.readTree(
+                rappCsarConfigurationHandler.getInstantiationPayload(rapp, rappInstance, compositionId));
+        assertEquals(jsonNode.get("compositionId").asText(), String.valueOf(compositionId));
+        JsonNode overrideParamsNode = jsonNode.at("/elements").elements().next().at("/properties/chart/overrideParams");
+        System.out.println(overrideParamsNode);
+        assertEquals(overrideParamsNode.get("appId").asText(), rappInstance.getRappInstanceId().toString());
+        assertEquals(overrideParamsNode.get("smeDiscoveryEndpoint").asText(),
+                rappsEnvironmentConfiguration.getSmeDiscoveryEndpoint());
     }
 
     @Test
@@ -116,7 +141,7 @@ class RappCsarConfigurationHandlerTest {
         assertThat(rappResources).isNotNull();
         assertNotNull(rappResources.getAcm().getCompositionDefinitions());
         assertThat(rappResources.getAcm().getCompositionInstances()).hasSize(4);
-        assertThat(rappResources.getSme().getProviderFunctions()).hasSize(4);
+        assertThat(rappResources.getSme().getProviderFunctions()).hasSize(3);
         assertThat(rappResources.getSme().getServiceApis()).hasSize(2);
         assertThat(rappResources.getSme().getInvokers()).hasSize(2);
         assertThat(rappResources.getDme().getProducerInfoTypes()).hasSize(2);
@@ -191,12 +216,17 @@ class RappCsarConfigurationHandlerTest {
     void testGetSmeInvokerPayload() {
         UUID rappId = UUID.randomUUID();
         RappSMEInstance rappSMEInstance = new RappSMEInstance();
-        rappSMEInstance.setServiceApis("invoker-app1");
+        rappSMEInstance.setInvokers("invoker-app1");
+        RappInstance rappInstance = new RappInstance();
+        rappInstance.setSme(rappSMEInstance);
         Rapp rapp =
                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
                         .build();
-        String smeProviderDomainPayload = rappCsarConfigurationHandler.getSmeInvokerPayload(rapp, rappSMEInstance);
-        assertNotNull(smeProviderDomainPayload);
+        JSONArray smeInvokerPayload =
+                new JSONArray(rappCsarConfigurationHandler.getSmeInvokerPayload(rapp, rappInstance));
+        assertNotNull(smeInvokerPayload);
+        assertEquals(smeInvokerPayload.getJSONObject(0).getString("apiInvokerInformation"),
+                rappInstance.getRappInstanceId().toString());
     }
 
     @Test
index b0c2f43..c220c54 100755 (executable)
@@ -25,10 +25,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doCallRealMethod;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.exception.RappValidationException;
 import java.io.ByteArrayOutputStream;
@@ -50,7 +49,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 @SpringBootTest
 @ContextConfiguration(classes = {ArtifactDefinitionValidator.class, RappValidationUtils.class, ObjectMapper.class,
-        RappCsarConfigurationHandler.class})
+        RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class})
 class ArtifactDefinitionValidatorTest {
 
     @Autowired
@@ -59,8 +58,7 @@ class ArtifactDefinitionValidatorTest {
     RappValidationUtils rappValidationUtils;
     String validCsarFileLocation = "src/test/resources/";
     String validRappFile = "valid-rapp-package.csar";
-    String invalidRappFile = "invalid-rapp-package.csar";
-    String invalidRappAsdEmptyFile = "invalid-rapp-package-empty-asd-yaml.csar";
+    String invalidRappMissingArtifactFile = "invalid-rapp-package-missing-artifact.csar";
 
     @Test
     void testCsarContainsValidAsdFile() throws IOException {
@@ -73,7 +71,7 @@ class ArtifactDefinitionValidatorTest {
 
     @Test
     void testCsarContainsValidAsdFileFailure() throws IOException {
-        String rappCsarPath = validCsarFileLocation + File.separator + invalidRappFile;
+        String rappCsarPath = validCsarFileLocation + File.separator + invalidRappMissingArtifactFile;
         MultipartFile multipartFile =
                 new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(),
                         new FileInputStream(rappCsarPath));
@@ -84,7 +82,6 @@ class ArtifactDefinitionValidatorTest {
     }
 
 
-
     @ParameterizedTest
     @NullSource
     @ValueSource(strings = {"{asasdasd"})
index 1d9079b..eb60567 100755 (executable)
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.doReturn;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.models.BeanTestConfiguration;
 import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.AsdMetadata;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.exception.RappValidationException;
@@ -54,7 +55,8 @@ import org.springframework.web.multipart.MultipartFile;
 
 @SpringBootTest
 @ContextConfiguration(classes = {BeanTestConfiguration.class, AsdDescriptorValidator.class, RappValidationUtils.class,
-        ObjectMapper.class, RappCsarConfigurationHandler.class, RappCacheService.class, CacheManager.class})
+        ObjectMapper.class, RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class,
+        RappCacheService.class, CacheManager.class})
 class AsdDescriptorValidatorTest {
 
     @Autowired
index 2b6e369..22ca62c 100755 (executable)
@@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.exception.RappValidationException;
 import java.io.File;
@@ -41,7 +42,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 @SpringBootTest
 @ContextConfiguration(classes = {FileExistenceValidator.class, RappValidationUtils.class, ObjectMapper.class,
-        RappCsarConfigurationHandler.class})
+        RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class})
 class FileExistenceValidatorTest {
 
     @Autowired
index 2166419..ac61c3e 100755 (executable)
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.models.BeanTestConfiguration;
 import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.exception.RappValidationException;
 import java.io.File;
@@ -47,7 +48,8 @@ import org.springframework.web.multipart.MultipartFile;
 @SpringBootTest
 @ContextConfiguration(classes = {BeanTestConfiguration.class, RappValidationHandler.class, NamingValidator.class,
         FileExistenceValidator.class, ArtifactDefinitionValidator.class, AsdDescriptorValidator.class,
-        RappValidationUtils.class, RappCsarConfigurationHandler.class, ObjectMapper.class, RappCacheService.class})
+        RappValidationUtils.class, RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class,
+        ObjectMapper.class, RappCacheService.class})
 class RappValidationHandlerTest {
 
     @Autowired
index da575dd..5245d54 100755 (executable)
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.csar.RappCsarPathProvider;
 import com.oransc.rappmanager.models.exception.RappValidationException;
@@ -43,7 +44,8 @@ import org.springframework.test.context.ContextConfiguration;
 import org.springframework.web.multipart.MultipartFile;
 
 @SpringBootTest
-@ContextConfiguration(classes = {RappValidationUtils.class, ObjectMapper.class, RappCsarConfigurationHandler.class})
+@ContextConfiguration(classes = {RappValidationUtils.class, ObjectMapper.class, RappsEnvironmentConfiguration.class,
+        RappCsarConfigurationHandler.class})
 class RappValidationUtilsTest {
 
     String validCsarFileLocation = "src/test/resources/";
@@ -87,7 +89,8 @@ class RappValidationUtilsTest {
         RappValidationException exception = assertThrows(RappValidationException.class,
                 () -> rappValidationUtils.getFileFromCsar(multipartFile, null));
         assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode());
-        assertEquals(String.format("Unable to get file %s from the multipart CSAR file", (Object) null), exception.getMessage());
+        assertEquals(String.format("Unable to get file %s from the multipart CSAR file", (Object) null),
+                exception.getMessage());
     }
 
     @Test
diff --git a/rapp-manager-models/src/test/resources/application.yaml b/rapp-manager-models/src/test/resources/application.yaml
new file mode 100644 (file)
index 0000000..2b28b08
--- /dev/null
@@ -0,0 +1,4 @@
+rappmanager:
+  rapps:
+    env:
+      smeDiscoveryEndpoint: http://localhost:53012/service-apis/v1/allServiceAPIs
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-empty-asd-yaml.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-empty-asd-yaml.csar
deleted file mode 100755 (executable)
index e146e59..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-empty-asd-yaml.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar
deleted file mode 100755 (executable)
index 39dd363..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-missing-artifact.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar
deleted file mode 100755 (executable)
index 03e466f..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-acm-composition.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-asd-yaml.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-no-asd-yaml.csar
deleted file mode 100755 (executable)
index dade078..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-asd-yaml.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar
deleted file mode 100755 (executable)
index 406a56d..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package-no-tosca.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/invalid-rapp-package.csar b/rapp-manager-models/src/test/resources/invalid-rapp-package.csar
deleted file mode 100755 (executable)
index d2d9e5e..0000000
Binary files a/rapp-manager-models/src/test/resources/invalid-rapp-package.csar and /dev/null differ
diff --git a/rapp-manager-models/src/test/resources/valid-rapp-package.csar b/rapp-manager-models/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index 1dddd4a..0000000
Binary files a/rapp-manager-models/src/test/resources/valid-rapp-package.csar and /dev/null differ
index 8463777..dd877d2 100755 (executable)
@@ -4,6 +4,7 @@
 * O-RAN-SC
 * %%
 * Copyright (C) 2023 Nordix Foundation
+* Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
     </properties>
-
-    <profiles>
-        <profile>
-            <id>Windows</id>
-            <activation>
-                <os>
-                    <family>Windows</family>
-                </os>
-            </activation>
-            <properties>
-                <script.extension>.bat</script.extension>
-                <file.separator>\</file.separator>
-            </properties>
-        </profile>
-        <profile>
-            <id>unix</id>
-            <activation>
-                <os>
-                    <family>unix</family>
-                </os>
-            </activation>
-            <properties>
-                <script.extension>.sh</script.extension>
-                <file.separator>/</file.separator>
-            </properties>
-        </profile>
-    </profiles>
-
     <dependencies>
         <dependency>
             <groupId>org.o-ran-sc.nonrtric.plt.rappmanager</groupId>
                     </execution>
                     <execution>
                         <id>initialize-sme-openapi-specs</id>
-                        <phase>initialize</phase>
+                        <phase>generate-sources</phase>
                         <goals>
                             <goal>exec</goal>
                         </goals>
                         <configuration>
+                            <workingDirectory>
+                                ${project.parent.basedir}/sme/capifcore
+                            </workingDirectory>
                             <executable>
-                                ..${file.separator}scripts${file.separator}init${file.separator}init-sme-spec${script.extension}
+                                go
                             </executable>
+                            <arguments>
+                                <argument>run</argument>
+                                <argument>getsmeswagger.go</argument>
+                            </arguments>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>${copy-resources-maven-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <id>copy-swagger-generator</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.parent.basedir}/sme/capifcore</outputDirectory>
+                            <resources>
+                                <resource>
+                                    <directory>${project.parent.basedir}/scripts/init/</directory>
+                                    <includes>
+                                        <include>getsmeswagger.go</include>
+                                    </includes>
+                                    <filtering>false</filtering>
+                                </resource>
+                            </resources>
                         </configuration>
                     </execution>
                 </executions>
index cab3ef8..8989e82 100755 (executable)
@@ -218,7 +218,7 @@ public class SmeDeployer implements RappDeployer {
     boolean createInvoker(Rapp rapp, RappInstance rappInstance) {
         logger.debug("Creating provider domain for Rapp {}", rapp.getName());
         try {
-            String invokerPayload = rappCsarConfigurationHandler.getSmeInvokerPayload(rapp, rappInstance.getSme());
+            String invokerPayload = rappCsarConfigurationHandler.getSmeInvokerPayload(rapp, rappInstance);
             if (invokerPayload != null) {
                 List<APIInvokerEnrolmentDetails> apiInvokerEnrolmentDetails =
                         objectMapper.readValue(invokerPayload, new TypeReference<>() { });
index 53d5b5d..3daab9e 100755 (executable)
@@ -30,6 +30,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.oransc.rappmanager.models.cache.RappCacheService;
+import com.oransc.rappmanager.models.configuration.RappsEnvironmentConfiguration;
 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
 import com.oransc.rappmanager.models.rapp.Rapp;
 import com.oransc.rappmanager.models.rapp.RappState;
@@ -63,8 +64,8 @@ import org.springframework.test.web.client.MockRestServiceServer;
 import org.springframework.web.client.RestTemplate;
 
 @SpringBootTest(classes = {SmeConfiguration.class, SmeDeployer.class, BeanTestConfiguration.class,
-        RappCsarConfigurationHandler.class, RappCacheService.class, RappInstanceStateMachineConfig.class,
-        RappInstanceStateMachine.class})
+        RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class, RappCacheService.class,
+        RappInstanceStateMachineConfig.class, RappInstanceStateMachine.class})
 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
 @AutoConfigureMockMvc
 class SmeDeployerTest {
@@ -532,7 +533,7 @@ class SmeDeployerTest {
         rappSMEInstance.setServiceApis("api-set-1");
         rappSMEInstance.setAefId("TEST_AEF_ID");
         rappSMEInstance.setApfId(String.valueOf(UUID.randomUUID()));
-        rappSMEInstance.setProviderFunction("aef-provider-function");
+        rappSMEInstance.setProviderFunction("provider-function-1");
         RappInstance rappInstance = new RappInstance();
         rappInstance.setSme(rappSMEInstance);
         return rappInstance;
diff --git a/rapp-manager-sme/src/test/resources/valid-rapp-package.csar b/rapp-manager-sme/src/test/resources/valid-rapp-package.csar
deleted file mode 100755 (executable)
index a269a48..0000000
Binary files a/rapp-manager-sme/src/test/resources/valid-rapp-package.csar and /dev/null differ
index 4491148..2e5a18a 100755 (executable)
           "repository": {
             "repoName": "local",
             "address": "UPDATE_THIS_CHART_MUSEUM_GET_CHARTS_URI"
+          },
+          "overrideParams": {
+            "appId": "DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID",
+            "smeDiscoveryEndpoint": "DO_NOT_CHANGE_THIS_SME_DISCOVERY_ENDPOINT"
           }
         }
       }
index b4416fb..a77ac5b 100755 (executable)
           "repository": {
             "repoName": "local",
             "address": "UPDATE_THIS_CHART_MUSEUM_GET_CHARTS_URI"
+          },
+          "overrideParams": {
+            "appId": "DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID",
+            "smeDiscoveryEndpoint": "DO_NOT_CHANGE_THIS_SME_DISCOVERY_ENDPOINT"
           }
         }
       }
index 612af40..0400730 100755 (executable)
@@ -1,6 +1,6 @@
 [
   {
-    "apiInvokerInformation": "Invoker App 1",
+    "apiInvokerInformation": "DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID",
     "apiList": [
       {}
     ],
index 27e1063..0ebeaad 100755 (executable)
@@ -1,6 +1,6 @@
 [
   {
-    "apiInvokerInformation": "Invoker App 2",
+    "apiInvokerInformation": "DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID",
     "apiList": [
       {}
     ],
index c019541..c37d288 100644 (file)
@@ -1,31 +1,35 @@
-{\r
-  "name": "K8DemoInstance0",\r
-  "version": "1.0.1",\r
-  "compositionId": "DO_NOT_CHANGE_THIS_COMPOSITION_ID",\r
-  "description": "Demo automation composition instance 0",\r
-  "elements": {\r
-    "d7be552e-bcc5-4478-b64d-797dbaec8f55": {\r
-      "id": "d7be552e-bcc5-4478-b64d-797dbaec8f55",\r
-      "definition": {\r
-        "name": "onap.policy.clamp.ac.element.K8S_StarterAutomationCompositionElement",\r
-        "version": "1.2.3"\r
-      },\r
-      "description": "Starter Automation Composition Element for the Hello World",\r
-      "properties": {\r
-        "chart": {\r
-          "chartId": {\r
-            "name": "hello-world-chart",\r
-            "version": "0.1.0"\r
-          },\r
-          "namespace": "nonrtric",\r
-          "releaseName": "hello-world-chart",\r
-          "podName": "hello-world-chart",\r
-          "repository": {\r
-            "repoName": "local",\r
-            "address": "UPDATE_THIS_CHART_MUSEUM_GET_CHARTS_URI"\r
-          }\r
-        }\r
-      }\r
-    }\r
-  }\r
+{
+  "name": "K8DemoInstance0",
+  "version": "1.0.1",
+  "compositionId": "DO_NOT_CHANGE_THIS_COMPOSITION_ID",
+  "description": "Demo automation composition instance 0",
+  "elements": {
+    "d7be552e-bcc5-4478-b64d-797dbaec8f55": {
+      "id": "d7be552e-bcc5-4478-b64d-797dbaec8f55",
+      "definition": {
+        "name": "onap.policy.clamp.ac.element.K8S_StarterAutomationCompositionElement",
+        "version": "1.2.3"
+      },
+      "description": "Starter Automation Composition Element for the Hello World",
+      "properties": {
+        "chart": {
+          "chartId": {
+            "name": "hello-world-chart",
+            "version": "0.1.0"
+          },
+          "namespace": "nonrtric",
+          "releaseName": "hello-world-chart",
+          "podName": "hello-world-chart",
+          "repository": {
+            "repoName": "local",
+            "address": "UPDATE_THIS_CHART_MUSEUM_GET_CHARTS_URI"
+          },
+          "overrideParams": {
+            "appId": "DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID",
+            "smeDiscoveryEndpoint": "DO_NOT_CHANGE_THIS_SME_DISCOVERY_ENDPOINT"
+          }
+        }
+      }
+    }
+  }
 }
\ No newline at end of file
diff --git a/scripts/init/generate-test-rapp-packages/generatetestrapppackages.go b/scripts/init/generate-test-rapp-packages/generatetestrapppackages.go
new file mode 100755 (executable)
index 0000000..8d39e68
--- /dev/null
@@ -0,0 +1,242 @@
+// -
+//
+//     ========================LICENSE_START=================================
+//     O-RAN-SC
+//     %%
+//     Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
+//     %%
+//     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.
+//     ========================LICENSE_END===================================
+package main
+
+import (
+       "archive/zip"
+       "encoding/json"
+       "fmt"
+       "io"
+       "os"
+       "path/filepath"
+       "strings"
+
+       cp "github.com/otiai10/copy"
+       "gopkg.in/yaml.v2"
+)
+
+func replaceStringsInDirectory(directory, stringToFind, stringToReplace string) error {
+       files, err := os.ReadDir(directory)
+       checkError(err)
+       for _, file := range files {
+               filePath := filepath.Join(directory, file.Name())
+               if file.IsDir() {
+                       if err := replaceStringsInDirectory(filePath, stringToFind, stringToReplace); err != nil {
+                               return err
+                       }
+               } else {
+                       if err := replaceString(filePath, stringToFind, stringToReplace); err != nil {
+                               return err
+                       }
+               }
+       }
+       return nil
+}
+
+func replaceString(fileLocation, stringToFind, stringToReplace string) error {
+       fileContent, err := os.ReadFile(fileLocation)
+       checkError(err)
+       if !strings.Contains(string(fileContent), stringToFind) {
+               return nil
+       }
+       updatedContent := strings.ReplaceAll(string(fileContent), stringToFind, stringToReplace)
+       err = os.WriteFile(fileLocation, []byte(updatedContent), 0644)
+       checkError(err)
+       return nil
+}
+
+func updateChartMuseumUri(directory string) error {
+       CHART_MUSEUM_GET_URI := "http://localhost:8879/charts"
+       CHART_MUSEUM_POST_URI := "http://localhost:8879/charts/api/charts"
+       err := replaceStringsInDirectory(directory, "UPDATE_THIS_CHART_MUSEUM_POST_CHARTS_URI", CHART_MUSEUM_POST_URI)
+       checkError(err)
+       err = replaceStringsInDirectory(directory, "UPDATE_THIS_CHART_MUSEUM_GET_CHARTS_URI", CHART_MUSEUM_GET_URI)
+       checkError(err)
+       return nil
+}
+
+func generateCsarPackage(directory, fileName string) error {
+       csarFile, err := os.Create(fileName)
+       checkError(err)
+       defer csarFile.Close()
+       csarWriter := zip.NewWriter(csarFile)
+       defer csarWriter.Close()
+       err = filepath.Walk(directory, func(filePath string, fileInfo os.FileInfo, err error) error {
+               if fileInfo.IsDir() {
+                       return nil
+               }
+               relPath, err := filepath.Rel(directory, filePath)
+               checkError(err)
+               relPath = strings.ReplaceAll(relPath, "\\", "/")
+               zipFile, err := csarWriter.Create(relPath)
+               checkError(err)
+               fsFile, err := os.Open(filePath)
+               checkError(err)
+               _, err = io.Copy(zipFile, fsFile)
+               checkError(err)
+               defer fsFile.Close()
+               return nil
+       })
+       checkError(err)
+       return nil
+}
+
+func createCsarAndCopy(directory string, paths ...string) error {
+       packageName := directory + ".csar"
+       err := generateCsarPackage(directory, packageName)
+       checkError(err)
+       for _, path := range paths {
+               fmt.Printf("Copying %s to %s \n", packageName, path)
+               copy(packageName, path+packageName)
+       }
+       os.Remove(packageName)
+       os.RemoveAll(directory)
+       return nil
+}
+
+func copy(srcFile string, targetFile string) {
+       data, err := os.ReadFile(srcFile)
+       checkError(err)
+       err = os.WriteFile(targetFile, data, 0644)
+       checkError(err)
+}
+
+func checkError(err error) error {
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+func removeYamlElement(filePath string, elements ...string) error {
+       fileData, err := os.ReadFile(filePath)
+       checkError(err)
+       var yamlContent map[interface{}]interface{}
+       err = yaml.Unmarshal(fileData, &yamlContent)
+       checkError(err)
+       index := len(elements) - 1
+       dataMap := yamlContent
+       for i := 0; i < index; i++ {
+               resultMap, ok := dataMap[elements[i]].(map[interface{}]interface{})
+               if !ok {
+                       return nil
+               }
+               dataMap = resultMap
+       }
+       delete(dataMap, elements[index])
+       updatedYamlContent, err := yaml.Marshal(&yamlContent)
+       checkError(err)
+       err = os.WriteFile(filePath, updatedYamlContent, 0644)
+       checkError(err)
+       return nil
+}
+
+func addJsonElement(filePath string, element string, index string) error {
+       fileData, err := os.ReadFile(filePath)
+       checkError(err)
+       var jsonContent map[string]interface{}
+       err = json.Unmarshal(fileData, &jsonContent)
+       checkError(err)
+       array, ok := jsonContent[index].([]interface{})
+       if !ok {
+               return nil
+       }
+       jsonContent[index] = append(array, element)
+       updatedJsonContent, err := json.Marshal(&jsonContent)
+       checkError(err)
+       err = os.WriteFile(filePath, updatedJsonContent, 0644)
+       checkError(err)
+       return nil
+}
+
+func main() {
+
+       SAMPLE_RAPP_GENERATOR := "sample-rapp-generator"
+       RAPP_BASE_PACKAGE := "rapp-all"
+       TEST_RESOURCES := "/src/test/resources/"
+       ACM_TEST_RESOURCES := "../rapp-manager-acm" + TEST_RESOURCES
+       APPLICATION_TEST_RESOURCES := "../rapp-manager-application" + TEST_RESOURCES
+       MODELS_TEST_RESOURCES := "../rapp-manager-models" + TEST_RESOURCES
+       DME_TEST_RESOURCES := "../rapp-manager-dme" + TEST_RESOURCES
+       SME_TEST_RESOURCES := "../rapp-manager-sme" + TEST_RESOURCES
+
+       if err := os.Chdir("../../../" + SAMPLE_RAPP_GENERATOR); err != nil {
+               fmt.Println("Error changing working directory:", err)
+               return
+       }
+
+       fmt.Println("Generating valid rApp package... ")
+       VALID_RAPP_PACKAGE_FOLDER_NAME := "valid-rapp-package"
+       cp.Copy(RAPP_BASE_PACKAGE, VALID_RAPP_PACKAGE_FOLDER_NAME)
+       updateChartMuseumUri(VALID_RAPP_PACKAGE_FOLDER_NAME)
+       createCsarAndCopy(VALID_RAPP_PACKAGE_FOLDER_NAME, ACM_TEST_RESOURCES, DME_TEST_RESOURCES, SME_TEST_RESOURCES, MODELS_TEST_RESOURCES, APPLICATION_TEST_RESOURCES)
+
+       fmt.Println("Generating valid rApp package without artifacts...")
+       VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME := "valid-rapp-package-no-artifacts"
+       cp.Copy(RAPP_BASE_PACKAGE, VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME)
+       updateChartMuseumUri(VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME)
+       removeYamlElement(VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME+"/Definitions/asd.yaml", "topology_template", "node_templates", "applicationServiceDescriptor", "artifacts")
+       createCsarAndCopy(VALID_RAPP_PACKAGE_NO_ARTIFACTS_FOLDER_NAME, APPLICATION_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package...")
+       INVALID_RAPP_PACKAGE_FOLDER_NAME := "invalid-rapp-package"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_FOLDER_NAME)
+       os.RemoveAll(INVALID_RAPP_PACKAGE_FOLDER_NAME + "/Files")
+       os.RemoveAll(INVALID_RAPP_PACKAGE_FOLDER_NAME + "/Artifacts")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_FOLDER_NAME, MODELS_TEST_RESOURCES, APPLICATION_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package without tosca...")
+       INVALID_RAPP_PACKAGE_NO_TOSCA_FOLDER_NAME := "invalid-rapp-package-no-tosca"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_NO_TOSCA_FOLDER_NAME)
+       os.Remove(INVALID_RAPP_PACKAGE_NO_TOSCA_FOLDER_NAME + "/TOSCA-Metadata/TOSCA.meta")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_NO_TOSCA_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package without asd yaml...")
+       INVALID_RAPP_PACKAGE_NO_ASD_YAML_FOLDER_NAME := "invalid-rapp-package-no-asd-yaml"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_NO_ASD_YAML_FOLDER_NAME)
+       os.Remove(INVALID_RAPP_PACKAGE_NO_ASD_YAML_FOLDER_NAME + "/Definitions/asd.yaml")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_NO_ASD_YAML_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package without ACM composition...")
+       INVALID_RAPP_PACKAGE_NO_ACM_COMPOSITION_FOLDER_NAME := "invalid-rapp-package-no-acm-composition"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_NO_ACM_COMPOSITION_FOLDER_NAME)
+       os.Remove(INVALID_RAPP_PACKAGE_NO_ACM_COMPOSITION_FOLDER_NAME + "/Files/Acm/definition/compositions.json")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_NO_ACM_COMPOSITION_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package without Artifacts...")
+       INVALID_RAPP_PACKAGE_MISSING_ARTIFACT_FOLDER_NAME := "invalid-rapp-package-missing-artifact"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_MISSING_ARTIFACT_FOLDER_NAME)
+       os.Remove(INVALID_RAPP_PACKAGE_MISSING_ARTIFACT_FOLDER_NAME + "/Artifacts/Deployment/HELM/orufhrecovery-1.0.0.tgz")
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_MISSING_ARTIFACT_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating invalid rApp package with empty asd yaml...")
+       INVALID_RAPP_PACKAGE_EMPTY_ASD_FOLDER_NAME := "invalid-rapp-package-empty-asd-yaml"
+       cp.Copy(RAPP_BASE_PACKAGE, INVALID_RAPP_PACKAGE_EMPTY_ASD_FOLDER_NAME)
+       os.Truncate(INVALID_RAPP_PACKAGE_EMPTY_ASD_FOLDER_NAME+"/Definitions/asd.yaml", 0)
+       createCsarAndCopy(INVALID_RAPP_PACKAGE_EMPTY_ASD_FOLDER_NAME, MODELS_TEST_RESOURCES)
+
+       fmt.Println("Generating valid rApp package with new dme info type...")
+       VALID_RAPP_PACKAGE_NEW_INFO_TYPE_FOLDER_NAME := "valid-rapp-package-new-info-type"
+       DME_PRODUCER_FILE := VALID_RAPP_PACKAGE_NEW_INFO_TYPE_FOLDER_NAME + "/Files/Dme/infoproducers/json-file-data-producer.json"
+       cp.Copy(RAPP_BASE_PACKAGE, VALID_RAPP_PACKAGE_NEW_INFO_TYPE_FOLDER_NAME)
+       addJsonElement(DME_PRODUCER_FILE, "new-info-type-not-available", "supported_info_types")
+       createCsarAndCopy(VALID_RAPP_PACKAGE_NEW_INFO_TYPE_FOLDER_NAME, DME_TEST_RESOURCES)
+
+}
diff --git a/scripts/init/generate-test-rapp-packages/go.mod b/scripts/init/generate-test-rapp-packages/go.mod
new file mode 100644 (file)
index 0000000..7be5956
--- /dev/null
@@ -0,0 +1,13 @@
+module oransc.org/nonrtric/rappmanager/generatetestrapppackages
+
+go 1.22
+
+require (
+       github.com/otiai10/copy v1.14.0
+       gopkg.in/yaml.v2 v2.4.0
+)
+
+require (
+       golang.org/x/sync v0.3.0 // indirect
+       golang.org/x/sys v0.8.0 // indirect
+)
diff --git a/scripts/init/generate-test-rapp-packages/go.sum b/scripts/init/generate-test-rapp-packages/go.sum
new file mode 100644 (file)
index 0000000..96997a3
--- /dev/null
@@ -0,0 +1,12 @@
+github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
+github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
+github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
+github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
+golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
+golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
+golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
+golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
index 65826a2..0e2c8ce 100755 (executable)
@@ -3,6 +3,7 @@
 //   O-RAN-SC
 //   %%
 //   Copyright (C) 2023: Nordix Foundation
+//   Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
 //   %%
 //   Licensed under the Apache License, Version 2.0 (the "License");
 //   you may not use this file except in compliance with the License.
 
 package main
 
-
 import (
+       "encoding/json"
+       "fmt"
        "github.com/getkin/kin-openapi/openapi3"
        log "github.com/sirupsen/logrus"
        "gopkg.in/yaml.v3"
-       "encoding/json"
-        "io/ioutil"
+       "io/ioutil"
+       "os"
 
+       "oransc.org/nonrtric/capifcore/internal/common"
+       "oransc.org/nonrtric/capifcore/internal/common29122"
+       "oransc.org/nonrtric/capifcore/internal/common29571"
        "oransc.org/nonrtric/capifcore/internal/invokermanagementapi"
        "oransc.org/nonrtric/capifcore/internal/providermanagementapi"
        "oransc.org/nonrtric/capifcore/internal/publishserviceapi"
-    "oransc.org/nonrtric/capifcore/internal/common"
-    "oransc.org/nonrtric/capifcore/internal/common29122"
-    "oransc.org/nonrtric/capifcore/internal/common29571"
 )
 
-func main() {
-       var swagger *openapi3.T
-       var err error
-
-       swagger,err = providermanagementapi.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Provider_Management_API.yaml")
-    }
-
-    swagger,err = publishserviceapi.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29222_CAPIF_Publish_Service_API.yaml")
-    }
-
-    swagger,err = invokermanagementapi.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Invoker_Management_API.yaml")
-    }
+type fn func() (swagger *openapi3.T, err error)
 
-    swagger,err = common.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "CommonData.yaml")
-    }
+var smeOpenApiFileLocation string = "../../openapi/sme/"
 
-    swagger,err = common29122.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29122_CommonData.yaml")
-    }
+func main() {
 
-    swagger,err = common29571.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29571_CommonData.yaml")
-    }
+       var err error
+       fmt.Println("Generating SME openapi spec...")
+       os.MkdirAll(smeOpenApiFileLocation, 0755)
+       if err == nil {
+               generateAndCopySwagger("TS29222_CAPIF_API_Provider_Management_API.yaml", providermanagementapi.GetSwagger)
+               generateAndCopySwagger("TS29222_CAPIF_Publish_Service_API.yaml", publishserviceapi.GetSwagger)
+               generateAndCopySwagger("TS29222_CAPIF_API_Invoker_Management_API.yaml", invokermanagementapi.GetSwagger)
+               generateAndCopySwagger("CommonData.yaml", common.GetSwagger)
+               generateAndCopySwagger("TS29122_CommonData.yaml", common29122.GetSwagger)
+               generateAndCopySwagger("TS29571_CommonData.yaml", common29571.GetSwagger)
+       }
 }
 
 func generateSwaggerYaml(swagger *openapi3.T, filename string) {
-    jsondataarr, jsondataarrerr := json.Marshal(&swagger)
-    if jsondataarrerr != nil {
-        log.Fatalf("Error loading json data from swagger \n: %s", jsondataarrerr)
-    }
+       jsondataarr, jsondataarrerr := json.Marshal(&swagger)
+       if jsondataarrerr != nil {
+               log.Fatalf("Error loading json data from swagger \n: %s", jsondataarrerr)
+       }
 
-    var data map[string]interface{}
-    if err := json.Unmarshal(jsondataarr, &data); err != nil {
-    log.Fatalf("Error loading json data to map \n: %s", jsondataarrerr)
-        log.Fatal(err)
-    }
+       var data map[string]interface{}
+       if err := json.Unmarshal(jsondataarr, &data); err != nil {
+               log.Fatalf("Error loading json data to map \n: %s", jsondataarrerr)
+               log.Fatal(err)
+       }
 
-    yamldataarr, yamldataarrerr := yaml.Marshal(&data)
-    if yamldataarrerr != nil {
-        log.Fatalf("Error loading json data map to array \n: %s", yamldataarrerr)
-    }
+       yamldataarr, yamldataarrerr := yaml.Marshal(&data)
+       if yamldataarrerr != nil {
+               log.Fatalf("Error loading json data map to array \n: %s", yamldataarrerr)
+       }
+
+       err2 := ioutil.WriteFile(filename, yamldataarr, 0755)
+       if err2 != nil {
+               log.Fatalf("Error writing provider yaml \n: %s", err2)
+       }
+}
 
-    err2 := ioutil.WriteFile(filename, yamldataarr, 0755)
-    if err2 != nil {
-        log.Fatalf("Error writing provider yaml \n: %s", err2)
-    }
-}
\ No newline at end of file
+func copy(srcFile string, targetFile string) error {
+       data, err := os.ReadFile(srcFile)
+       if err != nil {
+               return err
+       }
+       err = os.WriteFile(targetFile, data, 0644)
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+func generateAndCopySwagger(openApiFileName string, getSwagger fn) {
+       fmt.Printf("Generating %s...\n", openApiFileName)
+       swagger, err := getSwagger()
+       if err == nil {
+               generateSwaggerYaml(swagger, openApiFileName)
+               fmt.Printf("Copying %s to %s \n", openApiFileName, smeOpenApiFileLocation + openApiFileName)
+               copy(openApiFileName, smeOpenApiFileLocation +openApiFileName)
+       }
+}
diff --git a/scripts/init/init-sme-spec.bat b/scripts/init/init-sme-spec.bat
deleted file mode 100755 (executable)
index e9ee0b6..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-:: ============LICENSE_START===============================================
-::  Copyright (C) 2023 Nordix Foundation. All rights reserved.
-::  ========================================================================
-::  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.
-::  ============LICENSE_END=================================================
-::
-
-@echo off
-set SME_LOCATION="..\sme\capifcore"
-set SME_OPENAPI_LOCATION="..\..\openapi\sme"
-cp ..\scripts\init\getsmeswagger.go %SME_LOCATION%
-cd %SME_LOCATION%
-
-echo Generating SME openapi spec...
-
-IF EXIST getsmeswagger.go (
-  echo Generating...
-  go run getsmeswagger.go
-
-  echo Copying generated specs...
-  mkdir %SME_OPENAPI_LOCATION%
-  echo Copying CommonData.yaml
-  mv CommonData.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29122_CommonData.yaml
-  mv TS29122_CommonData.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29571_CommonData.yaml
-  mv TS29571_CommonData.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29222_CAPIF_API_Invoker_Management_API.yaml
-  mv TS29222_CAPIF_API_Invoker_Management_API.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29222_CAPIF_API_Provider_Management_API.yaml
-  mv TS29222_CAPIF_API_Provider_Management_API.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29222_CAPIF_Publish_Service_API.yaml
-  mv TS29222_CAPIF_Publish_Service_API.yaml %SME_OPENAPI_LOCATION%
-) ELSE (
-  echo Unable to find the openapi spec generator.
-)
diff --git a/scripts/init/init-sme-spec.sh b/scripts/init/init-sme-spec.sh
deleted file mode 100755 (executable)
index ee3e108..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/bash
-
-#  ============LICENSE_START===============================================
-#  Copyright (C) 2023 Nordix Foundation. All rights reserved.
-#  ========================================================================
-#  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.
-#  ============LICENSE_END=================================================
-#
-
-SME_LOCATION="../sme/capifcore"
-SME_OPENAPI_LOCATION="../../openapi/sme"
-cp ../scripts/init/getsmeswagger.go $SME_LOCATION
-cd $SME_LOCATION
-
-echo "Generating SME openapi spec..."
-
-if [ -f "getsmeswagger.go" ]; then
-  echo "Generating..."
-  go run getsmeswagger.go
-
-  echo "Copying generated specs..."
-  mkdir -p $SME_OPENAPI_LOCATION
-  echo "Copying CommonData.yaml"
-  mv CommonData.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29122_CommonData.yaml"
-  mv TS29122_CommonData.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29571_CommonData.yaml"
-  mv TS29571_CommonData.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29222_CAPIF_API_Invoker_Management_API.yaml"
-  mv TS29222_CAPIF_API_Invoker_Management_API.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29222_CAPIF_API_Provider_Management_API.yaml"
-  mv TS29222_CAPIF_API_Provider_Management_API.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29222_CAPIF_Publish_Service_API.yaml"
-  mv TS29222_CAPIF_Publish_Service_API.yaml $SME_OPENAPI_LOCATION
-else
-  echo "Unable to find the openapi spec generator."
-fi