diff options
29 files changed, 2499 insertions, 0 deletions
@@ -30,6 +30,7 @@ <snakeyaml-version>0.11</snakeyaml-version> <hamcrest-version>2.2</hamcrest-version> <equalsverifier-version>3.4.1</equalsverifier-version> + <so-core-version>1.7.0-SNAPSHOT</so-core-version> </properties> <build> diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml index 32af384..fb8b176 100644 --- a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml @@ -8,4 +8,40 @@ </parent> <artifactId>so-etsi-nfvo-ns-lcm-database-service</artifactId> <name>SO ETSI NFVO NS LCM Database Service</name> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + </dependency> + <dependency> + <groupId>org.flywaydb</groupId> + <artifactId>flyway-core</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <version>${equalsverifier-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.so</groupId> + <artifactId>common</artifactId> + <version>${so-core-version}</version> + <scope>test</scope> + </dependency> + </dependencies> </project>
\ No newline at end of file diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java new file mode 100644 index 0000000..6272505 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +public enum CancelModeType { + GRACEFUL, FORCEFUL; +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobAction.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobAction.java new file mode 100644 index 0000000..8a22689 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobAction.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum JobAction { + CREATE, INSTANTIATE, TERMINATE, DELETE; + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobStatusEnum.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobStatusEnum.java new file mode 100644 index 0000000..c67a3cc --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobStatusEnum.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum JobStatusEnum { + STARTING, STARTED, IN_PROGRESS, ERROR, FINISHED, FINISHED_WITH_ERROR; + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJob.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJob.java new file mode 100644 index 0000000..60b06e1 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJob.java @@ -0,0 +1,277 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils; + + +@Entity +@Table(name = "JOB") +public class NfvoJob { + + @Id + @Column(name = "JOB_ID", nullable = false) + private String jobId; + + @Column(name = "JOB_TYPE", nullable = false) + private String jobType; + + @Enumerated(EnumType.STRING) + @Column(name = "JOB_ACTION", nullable = false) + private JobAction jobAction; + + @Column(name = "RESOURCE_ID", nullable = false) + private String resourceId; + + @Column(name = "RESOURCE_NAME") + private String resourceName; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS", nullable = false) + private JobStatusEnum status; + + @Column(name = "START_TIME") + private LocalDateTime startTime; + + @Column(name = "END_TIME") + private LocalDateTime endTime; + + @Column(name = "PROGRESS") + private int progress; + + @Column(name = "PROCESS_INSTANCE_ID") + private String processInstanceId; + + @OneToMany(mappedBy = "nfvoJob", cascade = CascadeType.ALL, fetch = FetchType.EAGER) + private List<NfvoJobStatus> nfvoJobStatuses = new ArrayList<>(); + + public NfvoJob() { + this.jobId = UUID.randomUUID().toString(); + } + + public void setJobId(final String jobId) { + this.jobId = jobId; + } + + public String getJobId() { + return jobId; + } + + public NfvoJob jobId(final String jobId) { + this.jobId = jobId; + return this; + } + + public String getJobType() { + return jobType; + } + + public void setJobType(final String jobType) { + this.jobType = jobType; + } + + public NfvoJob jobType(final String jobType) { + this.jobType = jobType; + return this; + } + + public JobAction getJobAction() { + return jobAction; + } + + public void setJobAction(final JobAction jobAction) { + this.jobAction = jobAction; + } + + public NfvoJob jobAction(final JobAction jobAction) { + this.jobAction = jobAction; + return this; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(final String resourceId) { + this.resourceId = resourceId; + } + + public NfvoJob resourceId(final String resourceId) { + this.resourceId = resourceId; + return this; + } + + public JobStatusEnum getStatus() { + return status; + } + + public void setStatus(final JobStatusEnum status) { + this.status = status; + } + + public NfvoJob status(final JobStatusEnum status) { + this.status = status; + return this; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public void setStartTime(final LocalDateTime startTime) { + this.startTime = startTime; + } + + public NfvoJob startTime(final LocalDateTime startTime) { + this.startTime = startTime; + return this; + } + + public LocalDateTime getEndTime() { + return endTime; + } + + public void setEndTime(final LocalDateTime endTime) { + this.endTime = endTime; + } + + public NfvoJob endTime(final LocalDateTime endTime) { + this.endTime = endTime; + return this; + } + + public int getProgress() { + return progress; + } + + public void setProgress(final int progress) { + this.progress = progress; + } + + public NfvoJob progress(final int progress) { + this.progress = progress; + return this; + } + + public String getProcessInstanceId() { + return processInstanceId; + } + + public void setProcessInstanceId(final String processInstanceId) { + this.processInstanceId = processInstanceId; + } + + public NfvoJob processInstanceId(final String processInstanceId) { + this.processInstanceId = processInstanceId; + return this; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(final String resourceName) { + this.resourceName = resourceName; + } + + public NfvoJob resourceName(final String resourceName) { + this.resourceName = resourceName; + return this; + } + + public List<NfvoJobStatus> getNfvoJobStatuses() { + return nfvoJobStatuses; + } + + public void setJobStatuses(final List<NfvoJobStatus> nfvoJobStatuses) { + this.nfvoJobStatuses = nfvoJobStatuses; + } + + public NfvoJob nfvoJobStatuses(final List<NfvoJobStatus> nfvoJobStatuses) { + this.nfvoJobStatuses = nfvoJobStatuses; + return this; + } + + public NfvoJob nfvoJobStatus(final NfvoJobStatus nfvoJobStatus) { + nfvoJobStatus.setNfvoJob(this); + this.nfvoJobStatuses.add(nfvoJobStatus); + return this; + } + + @Override + public int hashCode() { + return Objects.hash(jobId, processInstanceId, jobType, jobAction, startTime, endTime, status, progress, + resourceId, resourceName, nfvoJobStatuses); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + if (obj instanceof NfvoJob) { + final NfvoJob other = (NfvoJob) obj; + return Objects.equals(jobId, other.jobId) && Objects.equals(processInstanceId, other.processInstanceId) + && Objects.equals(jobType, other.jobType) && Objects.equals(jobAction, other.jobAction) + && Objects.equals(progress, other.progress) && Objects.equals(status, other.status) + && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) + && Objects.equals(resourceId, other.resourceId) && Objects.equals(resourceName, other.resourceName) + && Utils.isEquals(nfvoJobStatuses, other.nfvoJobStatuses); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoJob {\n"); + sb.append(" jobId: ").append(toIndentedString(jobId)).append("\n"); + sb.append(" processInstanceId: ").append(toIndentedString(processInstanceId)).append("\n"); + sb.append(" jobType: ").append(toIndentedString(jobType)).append("\n"); + sb.append(" jobAction: ").append(toIndentedString(jobAction)).append("\n"); + sb.append(" progress: ").append(toIndentedString(progress)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" startTime: ").append(toIndentedString(startTime)).append("\n"); + sb.append(" endTime: ").append(toIndentedString(endTime)).append("\n"); + sb.append(" resId: ").append(toIndentedString(resourceId)).append("\n"); + sb.append(" resName: ").append(toIndentedString(resourceName)).append("\n"); + sb.append(" nfvoJobStatuses: ").append(toIndentedString(nfvoJobStatuses)).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java new file mode 100644 index 0000000..66ae0e5 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.time.LocalDateTime; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "JOB_STATUS") +public class NfvoJobStatus { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ID") + private int id; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS", nullable = false) + private JobStatusEnum status; + + @Column(name = "DESCRIPTION", columnDefinition = "LONGTEXT") + private String description; + + @Column(name = "UPDATED_TIME", nullable = false) + private LocalDateTime updatedTime; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "JOB_ID", nullable = false) + private NfvoJob nfvoJob; + + public int getId() { + return id; + } + + public JobStatusEnum getStatus() { + return status; + } + + public void setStatus(final JobStatusEnum status) { + this.status = status; + } + + public NfvoJobStatus status(final JobStatusEnum status) { + this.status = status; + return this; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public NfvoJobStatus description(final String description) { + this.description = description; + return this; + } + + public LocalDateTime getUpdatedTime() { + return updatedTime; + } + + public void setUpdatedTime(final LocalDateTime updatedTime) { + this.updatedTime = updatedTime; + } + + public NfvoJobStatus updatedTime(final LocalDateTime addTime) { + this.updatedTime = addTime; + return this; + } + + public NfvoJob getNfvoJob() { + return nfvoJob; + } + + public void setNfvoJob(final NfvoJob nfvoJob) { + this.nfvoJob = nfvoJob; + } + + public NfvoJobStatus nfvoJob(final NfvoJob nfvoJob) { + this.nfvoJob = nfvoJob; + return this; + } + + + @Override + public int hashCode() { + return Objects.hash(id, status, updatedTime, description, nfvoJob != null ? nfvoJob.getJobId() : 0); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + if (obj instanceof NfvoJobStatus) { + final NfvoJobStatus other = (NfvoJobStatus) obj; + return Objects.equals(id, other.id) && Objects.equals(status, other.status) + && Objects.equals(updatedTime, other.updatedTime) && Objects.equals(description, other.description) + && (nfvoJob == null ? other.nfvoJob == null + : other.nfvoJob != null && Objects.equals(nfvoJob.getJobId(), other.nfvoJob.getJobId())); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoJobStatus {\n"); + sb.append(" Id: ").append(toIndentedString(id)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" descp: ").append(toIndentedString(description)).append("\n"); + sb.append(" updatedTime: ").append(toIndentedString(updatedTime)).append("\n"); + sb.append(" jobId: ").append(nfvoJob != null ? toIndentedString(nfvoJob.getJobId()) : "").append("\n"); + sb.append("}"); + return sb.toString(); + } + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNfInst.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNfInst.java new file mode 100644 index 0000000..570355f --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNfInst.java @@ -0,0 +1,215 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.time.LocalDateTime; +import java.util.Objects; +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * @author mukeshsharma (mukeshsharma@est.tech) + */ +@Entity +@Table(name = "NF_INST") +public class NfvoNfInst { + + @Id + @Column(name = "NF_INST_ID", nullable = false) + private String nfInstId; + + @Column(name = "NAME") + private String name; + + @Column(name = "VNFD_ID") + private String vnfdId; + + @Column(name = "PACKAGE_ID") + private String packageId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "NS_INST_ID", nullable = false) + private NfvoNsInst nsInst; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS", nullable = false) + private State status; + + @Column(name = "CREATE_TIME") + private LocalDateTime createTime; + + @Column(name = "LAST_UPDATE_TIME") + private LocalDateTime lastUpdateTime; + + public NfvoNfInst() { + this.nfInstId = UUID.randomUUID().toString(); + } + + public String getNfInstId() { + return nfInstId; + } + + public void setNfInstId(final String nfInstId) { + this.nfInstId = nfInstId; + } + + public NfvoNfInst nfInstId(final String nfInstId) { + this.nfInstId = nfInstId; + return this; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public NfvoNfInst name(final String name) { + this.name = name; + return this; + } + + public String getVnfdId() { + return vnfdId; + } + + public void setVnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + } + + public NfvoNfInst vnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + return this; + } + + public String getPackageId() { + return packageId; + } + + public void setPackageId(final String packageId) { + this.packageId = packageId; + } + + public NfvoNfInst packageId(final String packageId) { + this.packageId = packageId; + return this; + } + + public NfvoNsInst getNsInst() { + return nsInst; + } + + public void setNsInst(final NfvoNsInst nsInst) { + this.nsInst = nsInst; + } + + public NfvoNfInst nfvoNsInst(final NfvoNsInst nfvoNsInst) { + this.nsInst = nfvoNsInst; + return this; + } + + public State getStatus() { + return status; + } + + public void setStatus(final State status) { + this.status = status; + } + + public NfvoNfInst status(final State status) { + this.status = status; + return this; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(final LocalDateTime createTime) { + this.createTime = createTime; + } + + public NfvoNfInst createTime(final LocalDateTime createTime) { + this.createTime = createTime; + return this; + } + + public LocalDateTime getLastUpdateTime() { + return lastUpdateTime; + } + + public void setLastUpdateTime(final LocalDateTime lastUpdateTime) { + this.lastUpdateTime = lastUpdateTime; + } + + public NfvoNfInst lastUpdateTime(final LocalDateTime lastUpdateTime) { + this.lastUpdateTime = lastUpdateTime; + return this; + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null || getClass() != object.getClass()) + return false; + final NfvoNfInst that = (NfvoNfInst) object; + return Objects.equals(nfInstId, that.nfInstId) && Objects.equals(name, that.name) + && Objects.equals(vnfdId, that.vnfdId) && Objects.equals(packageId, that.packageId) + && (nsInst == null ? that.nsInst == null : that.nsInst != null && Objects.equals(nsInst, that.nsInst)) + && Objects.equals(status, that.status) && Objects.equals(createTime, that.createTime) + && Objects.equals(lastUpdateTime, that.lastUpdateTime); + } + + @Override + public int hashCode() { + return Objects.hash(nfInstId, name, vnfdId, packageId, nsInst != null ? nsInst.getNsInstId() : 0, status, + createTime, lastUpdateTime); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoNfInst {\n"); + sb.append(" nfInstId: ").append(toIndentedString(nfInstId)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" vnfdId: ").append(toIndentedString(vnfdId)).append("\n"); + sb.append(" packageId: ").append(toIndentedString(packageId)).append("\n"); + sb.append(" nsInst: ").append(nsInst != null ? toIndentedString(nsInst.getNsInstId()) : null).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" createTime: ").append(toIndentedString(createTime)).append("\n"); + sb.append(" lastUpdateTime: ").append(toIndentedString(lastUpdateTime)).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java new file mode 100644 index 0000000..04f988c --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java @@ -0,0 +1,293 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Entity +@Table(name = "NS_INST") +public class NfvoNsInst { + + @Id + @Column(name = "NS_INST_ID", nullable = false) + private String nsInstId; + + @Column(name = "NAME", nullable = false) + private String name; + + @Column(name = "NS_PACKAGE_ID") + private String nsPackageId; + + @Column(name = "NSD_ID", nullable = false) + private String nsdId; + + @Column(name = "NSD_INVARIANT_ID", nullable = false) + private String nsdInvariantId; + + @Column(name = "DESCRIPTION", columnDefinition = "LONGTEXT") + private String description; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS", nullable = false) + private State status; + + @Column(name = "STATUS_UPDATED_TIME", nullable = false) + private LocalDateTime statusUpdatedTime; + + @Column(name = "GLOBAL_CUSTOMER_ID") + private String globalCustomerId; + + @Column(name = "SERVICE_TYPE") + private String serviceType; + + @OneToMany(mappedBy = "nsInst", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List<NfvoNfInst> nfvoNfInsts = new ArrayList<>(); + + @OneToMany(mappedBy = "nfvoNsInst", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List<NsLcmOpOcc> nsLcmOpOccs = new ArrayList<>(); + + public NfvoNsInst() { + this.nsInstId = UUID.randomUUID().toString(); + } + + public String getNsInstId() { + return nsInstId; + } + + public void setNsInstId(final String nsInstId) { + this.nsInstId = nsInstId; + } + + public NfvoNsInst nsInstId(final String nsInstId) { + this.nsInstId = nsInstId; + return this; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public NfvoNsInst name(final String name) { + this.name = name; + return this; + } + + public String getNsPackageId() { + return nsPackageId; + } + + public void setNsPackageId(final String nsPackageId) { + this.nsPackageId = nsPackageId; + } + + public NfvoNsInst nsPackageId(final String nsPackageId) { + this.nsPackageId = nsPackageId; + return this; + } + + public String getNsdId() { + return nsdId; + } + + public void setNsdId(final String nsdId) { + this.nsdId = nsdId; + } + + public NfvoNsInst nsdId(final String nsdId) { + this.nsdId = nsdId; + return this; + } + + public String getNsdInvariantId() { + return nsdInvariantId; + } + + public void setNsdInvariantId(final String nsdInvariantId) { + this.nsdInvariantId = nsdInvariantId; + } + + public NfvoNsInst nsdInvariantId(final String nsdInvariantId) { + this.nsdInvariantId = nsdInvariantId; + return this; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public NfvoNsInst description(final String description) { + this.description = description; + return this; + } + + public State getStatus() { + return status; + } + + public void setStatus(final State status) { + this.status = status; + } + + public NfvoNsInst status(final State status) { + this.status = status; + return this; + } + + public LocalDateTime getStatusUpdatedTime() { + return statusUpdatedTime; + } + + public void setStatusUpdatedTime(final LocalDateTime statusUpdatedTime) { + this.statusUpdatedTime = statusUpdatedTime; + } + + public NfvoNsInst statusUpdatedTime(final LocalDateTime statusUpdatedTime) { + this.statusUpdatedTime = statusUpdatedTime; + return this; + } + + public String getGlobalCustomerId() { + return globalCustomerId; + } + + public void setGlobalCustomerId(final String globalCustomerId) { + this.globalCustomerId = globalCustomerId; + } + + public NfvoNsInst globalCustomerId(final String globalCustomerId) { + this.globalCustomerId = globalCustomerId; + return this; + } + + public String getServiceType() { + return serviceType; + } + + public void setServiceType(final String serviceType) { + this.serviceType = serviceType; + } + + public NfvoNsInst serviceType(final String serviceType) { + this.serviceType = serviceType; + return this; + } + + public List<NfvoNfInst> getNfvoNfInsts() { + return nfvoNfInsts; + } + + public void setNfvoNfInsts(final List<NfvoNfInst> nfvoNfInsts) { + this.nfvoNfInsts = nfvoNfInsts; + } + + public NfvoNsInst nfvoNfInsts(final NfvoNfInst nfvoNfInsts) { + nfvoNfInsts.nfvoNsInst(this); + this.nfvoNfInsts.add(nfvoNfInsts); + return this; + } + + public List<NsLcmOpOcc> getNsLcmOpOccs() { + return nsLcmOpOccs; + } + + public void setNsLcmOpOccs(final List<NsLcmOpOcc> nsLcmOpOccs) { + this.nsLcmOpOccs = nsLcmOpOccs; + } + + public NfvoNsInst nsLcmOpOccs(final NsLcmOpOcc nsLcmOpOcc) { + nsLcmOpOcc.nfvoNsInst(this); + this.nsLcmOpOccs.add(nsLcmOpOcc); + return this; + } + + @Override + public int hashCode() { + return Objects.hash(nsInstId, name, nsPackageId, nsdId, nsdInvariantId, description, status, statusUpdatedTime, + globalCustomerId, serviceType, nfvoNfInsts, nsLcmOpOccs); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + if (obj instanceof NfvoNsInst) { + final NfvoNsInst other = (NfvoNsInst) obj; + return Objects.equals(nsInstId, other.nsInstId) && Objects.equals(name, other.name) + && Objects.equals(nsPackageId, other.nsPackageId) && Objects.equals(nsdId, other.nsdId) + && Objects.equals(nsdInvariantId, other.nsdInvariantId) + && Objects.equals(description, other.description) && Objects.equals(status, other.status) + && Objects.equals(statusUpdatedTime, other.statusUpdatedTime) + && Objects.equals(globalCustomerId, other.globalCustomerId) + && Objects.equals(serviceType, other.serviceType) && Objects.equals(nfvoNfInsts, other.nfvoNfInsts) + && Objects.equals(nsLcmOpOccs, other.nsLcmOpOccs); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoNsInst {\n"); + sb.append(" nsInstId: ").append(toIndentedString(nsInstId)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" nsPackageId: ").append(toIndentedString(nsPackageId)).append("\n"); + sb.append(" nsdId: ").append(toIndentedString(nsdId)).append("\n"); + sb.append(" nsdInvariantId: ").append(toIndentedString(nsdInvariantId)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" statusUpdatedTime: ").append(toIndentedString(statusUpdatedTime)).append("\n"); + sb.append(" globalCustomerId: ").append(toIndentedString(globalCustomerId)).append("\n"); + sb.append(" serviceType: ").append(toIndentedString(serviceType)).append("\n"); + sb.append(" nfvoNfInsts: ").append(toIndentedString(nfvoNfInsts)).append("\n"); + sb.append(" nsLcmOpOccs: ").append(toIndentedString(nsLcmOpOccs)).append("\n"); + + sb.append("}"); + return sb.toString(); + } + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java new file mode 100644 index 0000000..4846e5a --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java @@ -0,0 +1,253 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.time.LocalDateTime; +import java.util.Objects; +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * @author mukeshsharma(mukeshsharma@est.tech) + */ +@Entity +@Table(name = "NS_LCM_OP_OCCS") +public class NsLcmOpOcc { + + @Id + @Column(name = "ID", nullable = false) + private String id; + + @Enumerated(EnumType.STRING) + @Column(name = "OPERATION_STATE", nullable = false) + private OperationStateEnum operationState; + + @Column(name = "STATE_ENTERED_TIME") + private LocalDateTime stateEnteredTime; + + @Column(name = "START_TIME") + private LocalDateTime startTime; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "NS_INST_ID", nullable = false) + private NfvoNsInst nfvoNsInst; + + @Enumerated(EnumType.STRING) + @Column(name = "OPERATION", nullable = false) + private NsLcmOpType operation; + + @Column(name = "IS_AUTO_INVOCATION", nullable = false) + private boolean isAutoInvocation; + + @Column(name = "OPERATION_PARAMS", columnDefinition = "LONGTEXT", nullable = false) + private String operationParams; + + @Column(name = "IS_CANCEL_PENDING", nullable = false) + private boolean isCancelPending; + + @Enumerated(EnumType.STRING) + @Column(name = "CANCEL_MODE") + private CancelModeType cancelMode; + + public NsLcmOpOcc() { + this.id = UUID.randomUUID().toString(); + } + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public NsLcmOpOcc id(final String id) { + this.id = id; + return this; + } + + public OperationStateEnum getOperationState() { + return operationState; + } + + public void setOperationState(final OperationStateEnum operationState) { + this.operationState = operationState; + } + + public NsLcmOpOcc operationState(final OperationStateEnum operationState) { + this.operationState = operationState; + return this; + } + + public LocalDateTime getStateEnteredTime() { + return stateEnteredTime; + } + + public void setStateEnteredTime(final LocalDateTime stateEnteredTime) { + this.stateEnteredTime = stateEnteredTime; + } + + public NsLcmOpOcc stateEnteredTime(final LocalDateTime stateEnteredTime) { + this.stateEnteredTime = stateEnteredTime; + return this; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public void setStartTime(final LocalDateTime startTime) { + this.startTime = startTime; + } + + public NsLcmOpOcc startTime(final LocalDateTime startTime) { + this.startTime = startTime; + return this; + } + + public NfvoNsInst getNfvoNsInst() { + return nfvoNsInst; + } + + public void setNfvoNsInst(final NfvoNsInst nfvoNsInst) { + this.nfvoNsInst = nfvoNsInst; + } + + public NsLcmOpOcc nfvoNsInst(final NfvoNsInst nfvoNsInst) { + this.nfvoNsInst = nfvoNsInst; + return this; + } + + public NsLcmOpType getOperation() { + return operation; + } + + public void setOperation(final NsLcmOpType operation) { + this.operation = operation; + } + + public NsLcmOpOcc operation(final NsLcmOpType operation) { + this.operation = operation; + return this; + } + + public boolean getIsAutoInvocation() { + return isAutoInvocation; + } + + public void setIsAutoInvocation(final boolean isAutoInvocation) { + this.isAutoInvocation = isAutoInvocation; + } + + public NsLcmOpOcc isAutoInvocation(final boolean isAutoInvocation) { + this.isAutoInvocation = isAutoInvocation; + return this; + } + + public CancelModeType getCancelMode() { + return cancelMode; + } + + public void setCancelMode(final CancelModeType cancelMode) { + this.cancelMode = cancelMode; + } + + public NsLcmOpOcc cancelMode(final CancelModeType cancelMode) { + this.cancelMode = cancelMode; + return this; + } + + public String getOperationParams() { + return operationParams; + } + + public void setOperationParams(final String operationParams) { + this.operationParams = operationParams; + } + + public NsLcmOpOcc operationParams(final String operationParams) { + this.operationParams = operationParams; + return this; + } + + public boolean getIsCancelPending() { + return isCancelPending; + } + + public void setIsCancelPending(final boolean isCancelPending) { + this.isCancelPending = isCancelPending; + } + + public NsLcmOpOcc isCancelPending(final boolean isCancelPending) { + this.isCancelPending = isCancelPending; + return this; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + final NsLcmOpOcc that = (NsLcmOpOcc) obj; + return Objects.equals(id, that.id) && Objects.equals(operationState, that.operationState) + && Objects.equals(stateEnteredTime, that.stateEnteredTime) && Objects.equals(startTime, that.startTime) + && (nfvoNsInst == null ? that.nfvoNsInst == null + : that.nfvoNsInst != null && Objects.equals(nfvoNsInst, that.nfvoNsInst)) + && Objects.equals(operation, that.operation) && Objects.equals(isAutoInvocation, that.isAutoInvocation) + && Objects.equals(operationParams, that.operationParams) + && Objects.equals(isCancelPending, that.isCancelPending) && Objects.equals(cancelMode, that.cancelMode); + } + + @Override + public int hashCode() { + return Objects.hash(id, operationState, stateEnteredTime, startTime, + nfvoNsInst != null ? nfvoNsInst.getNsInstId() : 0, operation, isAutoInvocation, operationParams, + isCancelPending, cancelMode); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NsLcmOpOcc {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" operationState: ").append(toIndentedString(operationState)).append("\n"); + sb.append(" stateEnteredTime: ").append(toIndentedString(stateEnteredTime)).append("\n"); + sb.append(" startTime: ").append(toIndentedString(startTime)).append("\n"); + sb.append(" nfvoNsInst: ").append(nfvoNsInst != null ? toIndentedString(nfvoNsInst.getNsInstId()) : null) + .append("\n"); + sb.append(" operation: ").append(toIndentedString(operation)).append("\n"); + sb.append(" isAutoInvocation: ").append(toIndentedString(isAutoInvocation)).append("\n"); + sb.append(" operationParams: ").append(toIndentedString(operationParams)).append("\n"); + sb.append(" isCancelPending: ").append(toIndentedString(isCancelPending)).append("\n"); + sb.append(" cancelMode: ").append(toIndentedString(cancelMode)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpType.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpType.java new file mode 100644 index 0000000..351f961 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpType.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum NsLcmOpType { + INSTANTIATE, TERMINATE, SCALE, UPDATE, HEAL; +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/OperationStateEnum.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/OperationStateEnum.java new file mode 100644 index 0000000..236652e --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/OperationStateEnum.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum OperationStateEnum { + PROCESSING, COMPLETED, PARTIALLY_COMPLETED, FAILED_TEMP, FAILED, ROLLING_BACK, ROLLED_BACK; + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/State.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/State.java new file mode 100644 index 0000000..ce917dd --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/State.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum State { + NOT_INSTANTIATED, INSTANTIATING, INSTANTIATED, FAILED, TERMINATING; + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/Utils.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/Utils.java new file mode 100644 index 0000000..b84f95a --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/Utils.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils; + +import java.util.List; +import java.util.Objects; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class Utils { + + private Utils() {} + + public static final String toIndentedString(final Object object) { + return object == null ? "null" : object.toString().replace("\n", "\n "); + } + + + public static boolean isEquals(final List<?> first, List<?> second) { + if (first == null) { + return second == null; + } + + if (first.isEmpty()) { + return second.isEmpty(); + } + if ((first != null && second != null) && (first.size() == second.size())) { + for (int index = 0; index < first.size(); index++) { + if (!Objects.equals(first.get(index), second.get(index))) { + return false; + } + } + return true; + + } + return false; + } + + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/config/NfvoDatabaseConfiguration.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/config/NfvoDatabaseConfiguration.java new file mode 100644 index 0000000..1b4e409 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/config/NfvoDatabaseConfiguration.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.config; + +import static org.slf4j.LoggerFactory.getLogger; +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.flyway.FlywayDataSource; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jmx.export.MBeanExporter; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", + basePackages = {"org.onap.so.etsi.nfvo.ns.lcm.database.repository"}) +public class NfvoDatabaseConfiguration { + private static final Logger logger = getLogger(NfvoDatabaseConfiguration.class); + + private static final String PERSISTENCE_UNIT = "nfvo"; + private static final String NFVO_DATA_SOURCE_QUALIFIER = "nfvoDataSource"; + + @Autowired(required = false) + private MBeanExporter mBeanExporter; + + @Bean + @ConfigurationProperties(prefix = "spring.datasource.hikari.nfvo") + public HikariConfig nfvoDbConfig() { + logger.debug("Creating NFVO HikariConfig bean ... "); + return new HikariConfig(); + } + + @Primary + @FlywayDataSource + @Bean(name = NFVO_DATA_SOURCE_QUALIFIER) + public DataSource dataSource() { + if (mBeanExporter != null) { + mBeanExporter.addExcludedBean(NFVO_DATA_SOURCE_QUALIFIER); + } + logger.debug("Creating NFVO HikariDataSource bean ... "); + final HikariConfig hikariConfig = this.nfvoDbConfig(); + return new HikariDataSource(hikariConfig); + } + + @Primary + @Bean(name = "entityManagerFactory") + public LocalContainerEntityManagerFactoryBean entityManagerFactory(final EntityManagerFactoryBuilder builder, + @Qualifier(NFVO_DATA_SOURCE_QUALIFIER) final DataSource dataSource) { + return builder.dataSource(dataSource).packages(NfvoJob.class.getPackage().getName()) + .persistenceUnit(PERSISTENCE_UNIT).build(); + } + + @Primary + @Bean(name = "transactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("entityManagerFactory") final EntityManagerFactory entityManagerFactory) { + return new JpaTransactionManager(entityManagerFactory); + } + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NSLcmOpOccRepository.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NSLcmOpOccRepository.java new file mode 100644 index 0000000..d7f2f4c --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NSLcmOpOccRepository.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * @author mukeshsharma(mukeshsharma@est.tech) + */ +public interface NSLcmOpOccRepository extends JpaRepository<NsLcmOpOcc, String> { + + Optional<NsLcmOpOcc> findById(final String id); + + @Modifying(clearAutomatically = true) + @Query("UPDATE NsLcmOpOcc SET operationState = (:operationState) WHERE id = (:id)") + int updateNsLcmOpOccOperationState(@Param("id") final String id, + @Param("operationState") final OperationStateEnum operationState); +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobRepository.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobRepository.java new file mode 100644 index 0000000..220902c --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobRepository.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface NfvoJobRepository extends JpaRepository<NfvoJob, String>, RefreshableRepository<NfvoJob> { + + Optional<NfvoJob> findByResourceId(final String resourceId); + + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobStatusRepository.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobStatusRepository.java new file mode 100644 index 0000000..c3fe469 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobStatusRepository.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface NfvoJobStatusRepository extends CrudRepository<NfvoJobStatus, Integer> { +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNfInstRepository.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNfInstRepository.java new file mode 100644 index 0000000..f91a85f --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNfInstRepository.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +import java.util.List; +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * @author mukeshsharma(mukeshsharma@est.tech) + */ +public interface NfvoNfInstRepository extends JpaRepository<NfvoNfInst, String> { + + Optional<NfvoNfInst> findByNfInstId(final String nfInstId); + + List<NfvoNfInst> findByNsInstNsInstId(final String nsInstId); + + List<NfvoNfInst> findByNsInstNsInstIdAndName(final String nsInstId, final String name); + + @Modifying(clearAutomatically = true) + @Query("UPDATE NfvoNfInst SET status = (:state) WHERE nfInstId = (:nfInstId)") + int updateNfInstState(@Param("nfInstId") final String nfInstId, @Param("state") final State state); + + @Modifying(clearAutomatically = true) + @Query("DELETE FROM NfvoNfInst WHERE nfInstId = (:nfInstId)") + void deleteNfvoNfInstUsingNfInstId(@Param("nfInstId") final String nfInstId); +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java new file mode 100644 index 0000000..a64cf9b --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface NfvoNsInstRepository extends JpaRepository<NfvoNsInst, String> { + + Optional<NfvoNsInst> findByName(final String name); + + Optional<NfvoNsInst> findByNsInstId(final String nsInstId); + + boolean existsNfvoNsInstByName(final String name); + + @Modifying(clearAutomatically = true) + @Query("UPDATE NfvoNsInst SET status = (:state) WHERE nsInstId = (:nsInstId)") + int updateNsInstState(@Param("nsInstId") final String nsInstId, @Param("state") final State state); + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/RefreshableRepository.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/RefreshableRepository.java new file mode 100644 index 0000000..efa7130 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/RefreshableRepository.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface RefreshableRepository<T> { + + void refreshEntity(T entity); + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/RefreshableRepositoryImpl.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/RefreshableRepositoryImpl.java new file mode 100644 index 0000000..abd095f --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/RefreshableRepositoryImpl.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import org.springframework.stereotype.Repository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Repository +public class RefreshableRepositoryImpl<T> implements RefreshableRepository<T> { + + @PersistenceContext + private EntityManager entityManager; + + @Override + public void refreshEntity(final T entity) { + entityManager.refresh(entity); + + } + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java new file mode 100644 index 0000000..ec8777d --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.service; + +import java.util.List; +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NSLcmOpOccRepository; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoJobRepository; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoNfInstRepository; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoNsInstRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ + +@Service +public class DatabaseServiceProvider { + private static final Logger logger = LoggerFactory.getLogger(DatabaseServiceProvider.class); + + private final NfvoJobRepository nfvoJobRepository; + + private final NfvoNsInstRepository nfvoNsInstRepository; + + private final NfvoNfInstRepository nfvoNfInstRepository; + + private final NSLcmOpOccRepository nsLcmOpOccRepository; + + @Autowired + public DatabaseServiceProvider(final NfvoJobRepository nfvoJobRepository, + final NfvoNsInstRepository nfvoNsInstRepository, final NfvoNfInstRepository nfvoNfInstRepository, + final NSLcmOpOccRepository nsLcmOpOccRepository) { + this.nfvoJobRepository = nfvoJobRepository; + this.nfvoNsInstRepository = nfvoNsInstRepository; + this.nfvoNfInstRepository = nfvoNfInstRepository; + this.nsLcmOpOccRepository = nsLcmOpOccRepository; + } + + public boolean addJob(final NfvoJob job) { + logger.info("Adding NfvoJob: {} to database", job); + return nfvoJobRepository.saveAndFlush(job) != null; + } + + public Optional<NfvoJob> getJob(final String jobId) { + logger.info("Querying database for NfvoJob using jobId: {}", jobId); + return nfvoJobRepository.findById(jobId); + } + + @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ, readOnly = true) + public Optional<NfvoJob> getRefreshedJob(final String jobId) { + logger.info("Querying database for NfvoJob using jobId: {}", jobId); + final Optional<NfvoJob> optional = getJob(jobId); + if (optional.isPresent()) { + nfvoJobRepository.refreshEntity(optional.get()); + } + return optional; + } + + public Optional<NfvoJob> getJobByResourceId(final String resourceId) { + logger.info("Querying database for NfvoJob using resourceId: {}", resourceId); + return nfvoJobRepository.findByResourceId(resourceId); + } + + public boolean isNsInstExists(final String name) { + logger.info("Checking if NfvoNsInst entry exists in database using name: {}", name); + return nfvoNsInstRepository.existsNfvoNsInstByName(name); + } + + public boolean isNsInstExists(final String nsInstId, final String nfName) { + logger.info("Checking if NfvoNfInst entry exists in database using nsInstId: {} and nfName: {}", nsInstId, + nfName); + return nfvoNfInstRepository.findByNsInstNsInstIdAndName(nsInstId, nfName).isEmpty(); + } + + public boolean saveNfvoNsInst(final NfvoNsInst nfvoNsInst) { + logger.info("Saving NfvoNsInst: {} to database", nfvoNsInst); + return nfvoNsInstRepository.saveAndFlush(nfvoNsInst) != null; + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public boolean updateNsInstState(final String nsInstId, final State state) { + logger.info("Updating NfvoNsInst: {} State to {}", nsInstId, state); + return nfvoNsInstRepository.updateNsInstState(nsInstId, state) > 0; + } + + public Optional<NfvoNsInst> getNfvoNsInst(final String nsInstId) { + logger.info("Querying database for NfvoNsInst using nsInstId: {}", nsInstId); + return nfvoNsInstRepository.findById(nsInstId); + } + + public Optional<NfvoNsInst> getNfvoNsInstByName(final String name) { + logger.info("Querying database for NfvoNsInst using name: {}", name); + return nfvoNsInstRepository.findByName(name); + } + + public boolean saveNfvoNfInst(final NfvoNfInst nfvoNfInst) { + logger.info("Saving NfvoNfInst: {} to database", nfvoNfInst); + return nfvoNfInstRepository.saveAndFlush(nfvoNfInst) != null; + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public boolean updateNfInstState(final String nfInstId, final State state) { + logger.info("Updating NfvoNfInst: {} State to {}", nfInstId, state); + return nfvoNfInstRepository.updateNfInstState(nfInstId, state) > 0; + } + + public List<NfvoNfInst> getNfvoNfInstByNsInstId(final String nsInstId) { + logger.info("Querying database for NfvoNfInst using nsInstId: {}", nsInstId); + return nfvoNfInstRepository.findByNsInstNsInstId(nsInstId); + } + + public List<NfvoNfInst> getNfvoNfInstByNsInstIdAndNfName(final String nsInstId, final String name) { + logger.info("Querying database for NfvoNfInst using nsInstId: {} and name : {} ", nsInstId, name); + return nfvoNfInstRepository.findByNsInstNsInstIdAndName(nsInstId, name); + } + + public Optional<NfvoNfInst> getNfvoNfInst(final String nfInstId) { + logger.info("Querying database for NfvoNfInst using nfInstId: {}", nfInstId); + return nfvoNfInstRepository.findByNfInstId(nfInstId); + } + + public boolean isNfInstExists(final String nfInstId) { + logger.info("Checking if NfvoNfInst entry exists in database using nfInstId: {}", nfInstId); + return nfvoNfInstRepository.findByNfInstId(nfInstId).isPresent(); + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void deleteNfvoNfInst(final String nfInstId) { + logger.info("Deleting NfvoNfInst with nfInstId: {} from database", nfInstId); + nfvoNfInstRepository.deleteNfvoNfInstUsingNfInstId(nfInstId); + } + + public boolean addNSLcmOpOcc(final NsLcmOpOcc nsLcmOpOcc) { + logger.info("Adding NSLcmOpOcc: {} to database", nsLcmOpOcc); + return nsLcmOpOccRepository.saveAndFlush(nsLcmOpOcc) != null; + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public boolean updateNsLcmOpOccOperationState(final String id, final OperationStateEnum operationState) { + logger.info("Updating NsLcmOpOcc: {} operationState to {}", id, operationState); + return nsLcmOpOccRepository.updateNsLcmOpOccOperationState(id, operationState) > 0; + } + + public Optional<NsLcmOpOcc> getNsLcmOpOcc(final String id) { + logger.info("Querying database for NsLcmOpOcc using id: {}", id); + return nsLcmOpOccRepository.findById(id); + } + + public void deleteNfvoNsInst(final String nsInstId) { + logger.info("Deleting NfvoNsInst with nsInstId: {}", nsInstId); + nfvoNsInstRepository.deleteById(nsInstId); + } +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql new file mode 100644 index 0000000..85a732b --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql @@ -0,0 +1,75 @@ +use nfvo; + +CREATE TABLE IF NOT EXISTS `JOB` ( + `JOB_ID` varchar(255) NOT NULL, + `JOB_TYPE` varchar(255) NOT NULL, + `JOB_ACTION` varchar(255) NOT NULL, + `RESOURCE_ID` varchar(255) NOT NULL, + `RESOURCE_NAME` varchar(255) DEFAULT NULL, + `STATUS` varchar(255) NOT NULL, + `START_TIME` DATETIME DEFAULT NULL, + `END_TIME` DATETIME DEFAULT NULL, + `PROGRESS` int(11) DEFAULT NULL, + `PROCESS_INSTANCE_ID` varchar(255) DEFAULT NULL, + PRIMARY KEY (`JOB_ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + + +CREATE TABLE IF NOT EXISTS `JOB_STATUS` ( + `ID` INT NOT NULL AUTO_INCREMENT, + `UPDATED_TIME` DATETIME NOT NULL, + `DESCRIPTION` longtext DEFAULT NULL, + `STATUS` varchar(255) NOT NULL, + `JOB_ID` varchar(255) NOT NULL, + PRIMARY KEY (`ID`), + FOREIGN KEY (JOB_ID) + REFERENCES JOB(JOB_ID) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `NS_INST` ( + `NS_INST_ID` varchar(255) NOT NULL, + `NAME` varchar(255) NOT NULL, + `NS_PACKAGE_ID` varchar(255) DEFAULT NULL, + `NSD_ID` varchar(255) NOT NULL, + `NSD_INVARIANT_ID` varchar(255) NOT NULL, + `DESCRIPTION` longtext DEFAULT NULL, + `STATUS` varchar(255) NOT NULL, + `STATUS_UPDATED_TIME` DATETIME NOT NULL, + `GLOBAL_CUSTOMER_ID` varchar(255) DEFAULT NULL, + `SERVICE_TYPE` varchar(255) DEFAULT NULL, + PRIMARY KEY (`NS_INST_ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `NF_INST` ( + `NF_INST_ID` varchar(255) NOT NULL, + `NAME` varchar(255) DEFAULT NULL, + `VNFD_ID` varchar(255) DEFAULT NULL, + `PACKAGE_ID` varchar(255) DEFAULT NULL, + `NS_INST_ID` varchar(255) NOT NULL, + `STATUS` varchar(255) NOT NULL, + `CREATE_TIME` DATETIME DEFAULT NULL, + `LAST_UPDATE_TIME` DATETIME DEFAULT NULL, + PRIMARY KEY (`NF_INST_ID`), + FOREIGN KEY (NS_INST_ID) + REFERENCES NS_INST(NS_INST_ID) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `NS_LCM_OP_OCCS` ( + `ID` varchar(255) NOT NULL, + `OPERATION_STATE` varchar(255) NOT NULL, + `STATE_ENTERED_TIME` DATETIME DEFAULT NULL, + `START_TIME` DATETIME DEFAULT NULL, + `NS_INST_ID` varchar(255) NOT NULL, + `OPERATION` varchar(255) NOT NULL, + `IS_AUTO_INVOCATION` varchar(255) NOT NULL, + `OPERATION_PARAMS` longtext NOT NULL, + `IS_CANCEL_PENDING` varchar(255) NOT NULL, + `CANCEL_MODE` varchar(255) DEFAULT NULL, + PRIMARY KEY (`ID`), + FOREIGN KEY (NS_INST_ID) + REFERENCES NS_INST(NS_INST_ID) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java new file mode 100644 index 0000000..fcf7f9c --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java @@ -0,0 +1,180 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpType; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class DatabaseServiceProviderTest { + + private static final String RANDOM_ID = UUID.randomUUID().toString(); + private static final String DUMMY_NAME = "NAME"; + private static final LocalDateTime CURRENT_DATE_TIME = LocalDateTime.now(); + @Autowired + private DatabaseServiceProvider databaseServiceProvider; + + @Test + public void testAddJob_StoredInDatabase() { + final NfvoJob expected = new NfvoJob().jobType("TYPE").jobAction(JobAction.CREATE).resourceId(RANDOM_ID) + .resourceName(DUMMY_NAME).startTime(CURRENT_DATE_TIME).status(JobStatusEnum.STARTED); + databaseServiceProvider.addJob(expected); + + Optional<NfvoJob> actual = databaseServiceProvider.getJob(expected.getJobId()); + assertEquals(expected, actual.get()); + + actual = databaseServiceProvider.getRefreshedJob(expected.getJobId()); + assertEquals(expected, actual.get()); + + } + + @Test + public void testAddJobWithJobStatus_StoredInDatabase() { + final NfvoJob job = new NfvoJob().jobType("TYPE").jobAction(JobAction.CREATE).resourceId(RANDOM_ID) + .resourceName(DUMMY_NAME).startTime(CURRENT_DATE_TIME).status(JobStatusEnum.STARTED); + databaseServiceProvider.addJob(job); + + final NfvoJobStatus jobStatus = new NfvoJobStatus().status(JobStatusEnum.STARTED) + .description("Create NS workflow process started").updatedTime(CURRENT_DATE_TIME); + databaseServiceProvider.addJob(job.nfvoJobStatus(jobStatus)); + + final Optional<NfvoJob> actual = databaseServiceProvider.getJob(job.getJobId()); + final NfvoJob actualNfvoJob = actual.get(); + + assertEquals(job.getJobId(), actualNfvoJob.getJobId()); + assertFalse(actualNfvoJob.getNfvoJobStatuses().isEmpty()); + assertEquals(job.getJobId(), actualNfvoJob.getNfvoJobStatuses().get(0).getNfvoJob().getJobId()); + + } + + @Test + public void testAddNsInst_StoredInDatabase_ableTofindByQuery() { + + final NfvoNsInst nsInst = new NfvoNsInst().name(DUMMY_NAME).nsdId(RANDOM_ID).status(State.NOT_INSTANTIATED) + .nsdInvariantId(RANDOM_ID).statusUpdatedTime(CURRENT_DATE_TIME); + + databaseServiceProvider.saveNfvoNsInst(nsInst); + + Optional<NfvoNsInst> actual = databaseServiceProvider.getNfvoNsInst(nsInst.getNsInstId()); + NfvoNsInst actualNfvoNsInst = actual.get(); + assertEquals(nsInst.getNsInstId(), actualNfvoNsInst.getNsInstId()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdId()); + assertEquals(State.NOT_INSTANTIATED, actualNfvoNsInst.getStatus()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdInvariantId()); + assertEquals(CURRENT_DATE_TIME, actualNfvoNsInst.getStatusUpdatedTime()); + + actual = databaseServiceProvider.getNfvoNsInstByName(DUMMY_NAME); + actualNfvoNsInst = actual.get(); + + assertEquals(nsInst.getNsInstId(), actualNfvoNsInst.getNsInstId()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdId()); + assertEquals(State.NOT_INSTANTIATED, actualNfvoNsInst.getStatus()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdInvariantId()); + assertEquals(CURRENT_DATE_TIME, actualNfvoNsInst.getStatusUpdatedTime()); + + + assertTrue(databaseServiceProvider.isNsInstExists(DUMMY_NAME)); + } + + @Test + public void testAddNfInst_StoredInDatabase_ableTofindByQuery() { + + final NfvoNsInst nsInst = new NfvoNsInst().name(DUMMY_NAME).nsdId(RANDOM_ID).status(State.NOT_INSTANTIATED) + .nsdInvariantId(RANDOM_ID).statusUpdatedTime(CURRENT_DATE_TIME); + + databaseServiceProvider.saveNfvoNsInst(nsInst); + + final NfvoNfInst nfInst = new NfvoNfInst().nfvoNsInst(nsInst).name(DUMMY_NAME).vnfdId(RANDOM_ID) + .status(State.NOT_INSTANTIATED).createTime(CURRENT_DATE_TIME).lastUpdateTime(CURRENT_DATE_TIME); + databaseServiceProvider.saveNfvoNfInst(nfInst); + + final Optional<NfvoNfInst> actual = databaseServiceProvider.getNfvoNfInst(nfInst.getNfInstId()); + final NfvoNfInst actualNfvoNfInst = actual.get(); + assertEquals(nsInst.getNsInstId(), actualNfvoNfInst.getNsInst().getNsInstId()); + assertEquals(nfInst.getNfInstId(), actualNfvoNfInst.getNfInstId()); + assertEquals(nfInst.getName(), actualNfvoNfInst.getName()); + assertEquals(nfInst.getVnfdId(), actualNfvoNfInst.getVnfdId()); + assertEquals(nfInst.getStatus(), actualNfvoNfInst.getStatus()); + assertEquals(nfInst.getCreateTime(), actualNfvoNfInst.getCreateTime()); + assertEquals(nfInst.getLastUpdateTime(), actualNfvoNfInst.getLastUpdateTime()); + + + List<NfvoNfInst> nfvoNfInstList = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInst.getNsInstId()); + assertFalse(nfvoNfInstList.isEmpty()); + assertEquals(nsInst.getNsInstId(), nfvoNfInstList.get(0).getNsInst().getNsInstId()); + + nfvoNfInstList = databaseServiceProvider.getNfvoNfInstByNsInstIdAndNfName(nsInst.getNsInstId(), DUMMY_NAME); + + assertFalse(nfvoNfInstList.isEmpty()); + assertEquals(nsInst.getNsInstId(), nfvoNfInstList.get(0).getNsInst().getNsInstId()); + assertEquals(DUMMY_NAME, nfvoNfInstList.get(0).getName()); + } + + @Test + public void testAddNsLcmOpOcc_StoredInDatabase_ableTofindByQuery() { + + final NfvoNsInst nsInst = new NfvoNsInst().name(DUMMY_NAME).nsdId(RANDOM_ID).status(State.NOT_INSTANTIATED) + .nsdInvariantId(RANDOM_ID).statusUpdatedTime(CURRENT_DATE_TIME); + + databaseServiceProvider.saveNfvoNsInst(nsInst); + + final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().nfvoNsInst(nsInst).operationState(OperationStateEnum.PROCESSING) + .isCancelPending(false).isAutoInvocation(false).operation(NsLcmOpType.INSTANTIATE) + .startTime(CURRENT_DATE_TIME).stateEnteredTime(CURRENT_DATE_TIME).operationParams(""); + + + databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); + + final Optional<NsLcmOpOcc> actual = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOcc.getId()); + final NsLcmOpOcc actualLcmOpOcc = actual.get(); + assertEquals(nsLcmOpOcc.getId(), actualLcmOpOcc.getId()); + + assertEquals(nsInst.getNsInstId(), actualLcmOpOcc.getNfvoNsInst().getNsInstId()); + + } +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java new file mode 100644 index 0000000..5f033a2 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database; + +import javax.persistence.Entity; +import javax.persistence.Id; +import org.junit.Test; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.openpojo.rules.ToStringTester; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +public class PojoClassesTests { + + @Test + public void test_database_beans() throws ClassNotFoundException { + + final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()) + .with(new ToStringTester()).build(); + validator.validate(NfvoNsInst.class.getPackageName(), new FilterPackageInfo()); + } + + @Test + public void test_database_nfvoJob_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NfvoJob.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoJobStatus.class, new NfvoJobStatus().nfvoJob(new NfvoJob()), + new NfvoJobStatus().nfvoJob(new NfvoJob())) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } + + @Test + public void test_database_nfvoJobStatus_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NfvoJobStatus.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoJob.class, new NfvoJob(), new NfvoJob()) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } + + @Test + public void test_database_nfvoNsInst_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NfvoNsInst.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoNfInst.class, new NfvoNfInst(), new NfvoNfInst()) + .withPrefabValues(NsLcmOpOcc.class, new NsLcmOpOcc(), new NsLcmOpOcc()) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } + + @Test + public void test_database_nfvoNfInst_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NfvoNfInst.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoNsInst.class, new NfvoNsInst(), new NfvoNsInst()) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } + + @Test + public void test_database_nsLcmOpOcc_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NsLcmOpOcc.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoNsInst.class, new NfvoNsInst(), new NfvoNsInst()) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/TestApplication.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/TestApplication.java new file mode 100644 index 0000000..921cae2 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/TestApplication.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.etsi.nfvo.ns.lcm.database; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ComponentScan.Filter; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@SpringBootApplication(scanBasePackages = {"org.onap.so"}) +@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class}) +@ComponentScan(basePackages = {"org.onap"}, + excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)}) +public class TestApplication { + + public static void main(final String[] args) { + new SpringApplication(TestApplication.class).run(args); + } + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/UtilsTest.java b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/UtilsTest.java new file mode 100644 index 0000000..632bda9 --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/UtilsTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.util.Arrays; +import java.util.Collections; +import org.junit.Test; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class UtilsTest { + + @Test + public void testTwoEmptyLists_equal() { + assertTrue(Utils.isEquals(Collections.emptyList(), Collections.emptyList())); + } + + @Test + public void testEmptyListAndNonEmpty_notEqual() { + assertFalse(Utils.isEquals(Collections.emptyList(), Arrays.asList("A"))); + } + + @Test + public void testTwoNullLists_equal() { + assertTrue(Utils.isEquals(null, null)); + } + + @Test + public void testNullListAndEmptyList_notEqual() { + assertFalse(Utils.isEquals(null, Collections.emptyList())); + } + + @Test + public void testTwoNotEmptyListsContainSameObjects_equal() { + assertTrue(Utils.isEquals(Arrays.asList("A"), Arrays.asList("A"))); + } + + @Test + public void testTwoNotEmptyListsContainsDifferentObjects_equal() { + assertFalse(Utils.isEquals(Arrays.asList("A"), Arrays.asList(1))); + } + + +} diff --git a/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml new file mode 100644 index 0000000..adc36ac --- /dev/null +++ b/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml @@ -0,0 +1,31 @@ +# Copyright © 2020 Nordix Foundation +# +# 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. +spring: + main: + web-application-type: none + datasource: + hikari: + nfvo: + jdbcUrl: jdbc:h2:mem:nfvo;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS nfvo; + driver-class-name: org.h2.Driver + pool-name: ns-lcm-bpmn-pool + registerMbeans: true + jpa: + generate-ddl: true + hibernate: + ddl-auto: create +hibernate: + dialect: org.hibernate.dialect.H2Dialect + hbm2ddl: + auto: create
\ No newline at end of file |