<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>
/*
* ============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: "*"
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);
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));
* 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>
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;
--- /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