diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2021-02-03 15:55:53 +0000 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2021-02-03 15:55:56 +0000 |
commit | 10f0ec92cc2636b883db807a58448617cc09d259 (patch) | |
tree | 0311a9dbe4bb0a97790cf44b943f9fdd9a8b8f42 /so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java | |
parent | a5523bf18bb8ce9195a7d384f108c913ba84ae67 (diff) |
Adding ns-lcm-database-service module
Change-Id: I03a3f5aa6a1269ff3083d95a9b6517bd21b758ef
Issue-ID: SO-3485
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java')
21 files changed, 1973 insertions, 0 deletions
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); + } +} |