## 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
### 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 ---
/*-
* ============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.
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;
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);
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
<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>
<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>
<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>
@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);
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;
@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 {
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
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:
/*
* ============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.
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;
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();
@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));
--- /dev/null
+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: "*"
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;
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
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;
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 {
--- /dev/null
+/*-
+ * ============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
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;
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) {
}
-
-
public String getSmeProviderDomainPayload(Rapp rapp, RappSMEInstance rappSMEInstance) {
return getPayload(rapp, getResourceUri(RappCsarPathProvider.SME_PROVIDER_FUNCS_LOCATION,
rappSMEInstance.getProviderFunction()));
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) {
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;
import org.springframework.test.context.ContextConfiguration;
@SpringBootTest
-@ContextConfiguration(classes = {ObjectMapper.class, RappCsarConfigurationHandler.class})
+@ContextConfiguration(
+ classes = {ObjectMapper.class, RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class})
class RappServiceEnablerTest {
@Autowired
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;
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/";
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
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);
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
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;
@SpringBootTest
@ContextConfiguration(classes = {ArtifactDefinitionValidator.class, RappValidationUtils.class, ObjectMapper.class,
- RappCsarConfigurationHandler.class})
+ RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class})
class ArtifactDefinitionValidatorTest {
@Autowired
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 {
@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));
}
-
@ParameterizedTest
@NullSource
@ValueSource(strings = {"{asasdasd"})
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;
@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
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;
@SpringBootTest
@ContextConfiguration(classes = {FileExistenceValidator.class, RappValidationUtils.class, ObjectMapper.class,
- RappCsarConfigurationHandler.class})
+ RappsEnvironmentConfiguration.class, RappCsarConfigurationHandler.class})
class FileExistenceValidatorTest {
@Autowired
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;
@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
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;
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/";
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
--- /dev/null
+rappmanager:
+ rapps:
+ env:
+ smeDiscoveryEndpoint: http://localhost:53012/service-apis/v1/allServiceAPIs
* 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>
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<>() { });
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;
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 {
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;
"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"
}
}
}
"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"
}
}
}
[
{
- "apiInvokerInformation": "Invoker App 1",
+ "apiInvokerInformation": "DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID",
"apiList": [
{}
],
[
{
- "apiInvokerInformation": "Invoker App 2",
+ "apiInvokerInformation": "DO_NOT_CHANGE_THIS_RAPP_INSTANCE_ID",
"apiList": [
{}
],
-{\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
--- /dev/null
+// -
+//
+// ========================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)
+
+}
--- /dev/null
+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
+)
--- /dev/null
+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=
// 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)
+ }
+}
+++ /dev/null
-:: ============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.
-)
+++ /dev/null
-#!/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