aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/vnfd/vnfd.go
blob: 0fb81dbd44d215438b923c490ff1e72a95d53428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright 2018 Intel Corporation, Inc
 *
 * 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.
 */

package vnfd

import (
	"k8splugin/db"
	"log"

	uuid "github.com/hashicorp/go-uuid"
	pkgerrors "github.com/pkg/errors"
)

// VNFDefinition contains the parameters needed for VNF Definitions
// It implements the interface for managing the definitions
type VNFDefinition struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	UUID        string `json:"uuid,omitempty"`
	ServiceType string `json:"service-type"`
}

// VNFDefinitionInterface is an interface exposes the VNFDefinition functionality
type VNFDefinitionInterface interface {
	Create(vnfd VNFDefinition) (VNFDefinition, error)
	List() ([]VNFDefinition, error)
	Get(vnfID string) (VNFDefinition, error)
	Delete(vnfID string) error
}

// VNFDefinitionClient implements the VNFDefinitionInterface
// It will also be used to maintain some localized state
type VNFDefinitionClient struct {
	keyPrefix string
}

// GetVNFDClient Returns an instance of the VNFDefinitionClient
// which implements the VNFDefinitionInterface interface
func GetVNFDClient() *VNFDefinitionClient {
	return &VNFDefinitionClient{
		keyPrefix: "vnfd/"}
}

// Create creates an entry for the VNF in the database
func (v *VNFDefinitionClient) Create(vnfd VNFDefinition) (VNFDefinition, error) {
	// If UUID is empty, we will generate one
	if vnfd.UUID == "" {
		vnfd.UUID, _ = uuid.GenerateUUID()
	}
	key := v.keyPrefix + vnfd.UUID

	serData, err := db.Serialize(v)
	if err != nil {
		return VNFDefinition{}, pkgerrors.Wrap(err, "Serialize VNF Definition")
	}

	err = db.DBconn.Create(key, serData)
	if err != nil {
		return VNFDefinition{}, pkgerrors.Wrap(err, "Creating DB Entry")
	}

	return vnfd, nil
}

// List lists all vnf entries in the database
func (v *VNFDefinitionClient) List() ([]VNFDefinition, error) {
	strArray, err := db.DBconn.ReadAll(v.keyPrefix)
	if err != nil {
		return []VNFDefinition{}, pkgerrors.Wrap(err, "Listing VNF Definitions")
	}

	var retData []VNFDefinition

	for _, key := range strArray {
		value, err := db.DBconn.Read(key)
		if err != nil {
			log.Printf("Error Reading Key: %s", key)
			continue
		}
		if value != "" {
			vnfd := VNFDefinition{}
			err = db.DeSerialize(value, &vnfd)
			if err != nil {
				log.Printf("Error Deserializing Value: %s", value)
				continue
			}
			retData = append(retData, vnfd)
		}
	}

	return retData, nil
}

// Get returns the VNF Definition for corresponding ID
func (v *VNFDefinitionClient) Get(vnfID string) (VNFDefinition, error) {
	value, err := db.DBconn.Read(v.keyPrefix + vnfID)
	if err != nil {
		return VNFDefinition{}, pkgerrors.Wrap(err, "Get VNF Definitions")
	}

	if value != "" {
		vnfd := VNFDefinition{}
		err = db.DeSerialize(value, &vnfd)
		if err != nil {
			return VNFDefinition{}, pkgerrors.Wrap(err, "Deserializing Value")
		}
		return vnfd, nil
	}

	return VNFDefinition{}, pkgerrors.New("Error getting VNF Definition")
}

// Delete deletes the VNF Definition from database
func (v *VNFDefinitionClient) Delete(vnfID string) error {
	err := db.DBconn.Delete(v.keyPrefix + vnfID)
	if err != nil {
		return pkgerrors.Wrap(err, "Delete VNF Definitions")
	}

	return nil
}
n class="n">outputDirectory}" srcdir="${basedir}/src/main/groovy/" listfiles="true"> <classpath refid="maven.compile.classpath" /> </groovyc> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> <execution> <id>test-compile</id> <phase>test-compile</phase> <configuration> <tasks> <mkdir dir="${basedir}/src/test/groovy" /> <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc"> <classpath refid="maven.test.classpath" /> </taskdef> <mkdir dir="${project.build.testOutputDirectory}" /> <groovyc destdir="${project.build.testOutputDirectory}" srcdir="${basedir}/src/test/groovy/" listfiles="true"> <classpath refid="maven.test.classpath" /> </groovyc> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <executions> <execution> <id>default-test</id> <goals> <goal>test</goal> </goals> <configuration> <includes> <include>**/AllTestSuites.java</include> </includes> </configuration> </execution> <execution> <id>non-spring-tests</id> <goals> <goal>test</goal> </goals> <configuration> <includes> <include>**/NonSpringSuite.java</include> </includes> </configuration> </execution> <execution> <id>groovy-tests</id> <goals> <goal>test</goal> </goals> <configuration> <includes> <include>**/AllGroovyTestSuites.java</include> </includes> </configuration> </execution> </executions> </plugin> </plugins> <pluginManagement> <plugins> <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. --> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId> org.apache.maven.plugins </groupId> <artifactId> maven-antrun-plugin </artifactId> <versionRange> [1.3,) </versionRange> <goals> <goal>run</goal> </goals> </pluginExecutionFilter> <action> <ignore></ignore> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> </build> <dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from camunda --> <groupId>org.camunda.bpm</groupId> <artifactId>camunda-bom</artifactId> <version>${camunda.version}</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.camunda.bpm.springboot</groupId> <artifactId>camunda-bpm-spring-boot-starter</artifactId> <version>${camunda.springboot.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-wiremock</artifactId> <version>1.2.4.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.camunda.bpm.extension.mockito</groupId> <artifactId>camunda-bpm-mockito</artifactId> <version>3.2.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.camunda.connect</groupId> <artifactId>camunda-connect-connectors-all</artifactId> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.3</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <!-- Needed for InMemoryH2Test --> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> </dependency> <dependency> <groupId>org.onap.so</groupId> <artifactId>MSOCoreBPMN</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.onap.so</groupId> <artifactId>mso-catalog-db</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.onap.so</groupId> <artifactId>mso-requests-db</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.onap.so</groupId> <artifactId>common</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.onap.so.adapters</groupId> <artifactId>mso-adapters-rest-interface</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> </dependency> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>${jax.ws.rs}</version> </dependency> <dependency> <groupId>org.onap.appc.client</groupId> <artifactId>client-lib</artifactId> <version>1.4.4</version> <exclusions> <exclusion> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> </exclusion> <exclusion> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> </exclusion> <exclusion> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.onap.appc.client</groupId> <artifactId>client-kit</artifactId> <version>1.4.4</version> <exclusions> <exclusion> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-common</artifactId> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> </dependency> <dependency> <groupId>org.glassfish.jersey.inject</groupId> <artifactId>jersey-hk2</artifactId> <version>2.26</version> </dependency> <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> </dependency> <dependency> <groupId>org.onap.sdc.sdc-tosca</groupId> <artifactId>sdc-tosca</artifactId> <version>1.4.4</version> </dependency> <dependency> <groupId>org.onap.sdc.jtosca</groupId> <artifactId>jtosca</artifactId> <version>1.4.4</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>uk.co.blackpepper.bowman</groupId> <artifactId>bowman-client</artifactId> <version>0.3.0</version> </dependency> <dependency> <groupId>pl.pragmatists</groupId> <artifactId>JUnitParams</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>ch.vorburger.mariaDB4j</groupId> <artifactId>mariaDB4j</artifactId> <version>2.2.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-wiremock</artifactId> <version>1.2.4.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.11.1</version> <scope>test</scope> </dependency> </dependencies> </project>