diff options
author | 2020-08-31 00:14:37 +0100 | |
---|---|---|
committer | 2020-09-04 12:43:32 +0100 | |
commit | c78c3e45c2e5d18f6dfa15f74270a52aea7defe4 (patch) | |
tree | 48bf4584dada0e8ea8c2bc0c6652acfa5d295cf7 /so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap | |
parent | 2f173c2b6dbe21120763f01efcf1e12080ab1f5f (diff) |
Initialise NFVO Database Tables
Adding Entity files and SQL Script for initalising the NFVO DB using flyway.
Also updated order of dependencies between pom.xmls with the so-etsi-nfvo module.
Change-Id: I9ba682398df5a6cba22452f08caa565dec631b5d
Issue-ID: SO-3159
Signed-off-by: rope252 <gareth.roper@est.tech>
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap')
12 files changed, 1443 insertions, 0 deletions
diff --git a/so-etsi-nfvo/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/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 0000000000..50573b42f5 --- /dev/null +++ b/so-etsi-nfvo/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,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 JobAction { + CREATE, INSTANTIATE, TERMINATE, DELETE; + +} diff --git a/so-etsi-nfvo/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/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 0000000000..c67a3cc692 --- /dev/null +++ b/so-etsi-nfvo/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/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/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 0000000000..9453caac9e --- /dev/null +++ b/so-etsi-nfvo/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,274 @@ +/*- + * ============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") + private String jobId; + + @Column(name = "JOB_TYPE") + private String jobType; + + @Enumerated(EnumType.STRING) + @Column(name = "JOB_ACTION") + private JobAction jobAction; + + @Column(name = "RESOURCE_ID") + private String resourceId; + + @Column(name = "RESOURCE_NAME") + private String resourceName; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS") + 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 (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(status, other.status) && 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/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/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 0000000000..9bd05924ad --- /dev/null +++ b/so-etsi-nfvo/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,147 @@ +/*- + * ============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") + private JobStatusEnum status; + + @Column(name = "DESCRIPTION") + private String description; + + @Column(name = "UPDATED_TIME") + private LocalDateTime updatedTime; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "JOB_ID") + 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.getJobId()); + } + + @Override + public boolean equals(final Object obj) { + + 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) + && 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/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/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 0000000000..e901e10596 --- /dev/null +++ b/so-etsi-nfvo/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,213 @@ +/*- + * ============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") + 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") + private NfvoNsInst nsInst; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS") + 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) + && 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, 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/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/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 0000000000..fdd053c49e --- /dev/null +++ b/so-etsi-nfvo/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,289 @@ +/*- + * ============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") + private String nsInstId; + + @Column(name = "NAME") + private String name; + + @Column(name = "NS_PACKAGE_ID") + private String nsPackageId; + + @Column(name = "NSD_ID") + private String nsdId; + + @Column(name = "NSD_INVARIANT_ID") + private String nsdInvariantId; + + @Column(name = "DESCRIPTION") + private String description; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS") + private State status; + + @Column(name = "STATUS_UPDATED_TIME") + 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 (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/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/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 0000000000..7549b49264 --- /dev/null +++ b/so-etsi-nfvo/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,233 @@ +/*- + * ============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") + private String id; + + @Enumerated(EnumType.STRING) + @Column(name = "OPERATION_STATE") + 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") + private NfvoNsInst nfvoNsInst; + + @Enumerated(EnumType.STRING) + @Column(name = "OPERATION") + private NsLcmOpType operation; + + @Column(name = "IS_AUTO_INNOVATION") + private boolean isAutoInnovation; + + @Column(name = "OPERATION_PARAMS") + private String operationParams; + + @Column(name = "IS_CANCEL_PENDING") + private boolean isCancelPending; + + 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 getIsAutoInnovation() { + return isAutoInnovation; + } + + public void setIsAutoInnovation(final boolean isAutoInnovation) { + this.isAutoInnovation = isAutoInnovation; + } + + public NsLcmOpOcc isAutoInnovation(final boolean isAutoInnovation) { + this.isAutoInnovation = isAutoInnovation; + 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 object) { + if (this == object) + return true; + if (object == null || getClass() != object.getClass()) + return false; + final NsLcmOpOcc that = (NsLcmOpOcc) object; + return Objects.equals(id, that.id) && Objects.equals(operationState, that.operationState) + && Objects.equals(stateEnteredTime, that.stateEnteredTime) && Objects.equals(startTime, that.startTime) + && Objects.equals(nfvoNsInst, that.nfvoNsInst) && Objects.equals(operation, that.operation) + && Objects.equals(isAutoInnovation, that.isAutoInnovation) + && Objects.equals(operationParams, that.operationParams) + && Objects.equals(isCancelPending, that.isCancelPending); + } + + @Override + public int hashCode() { + return Objects.hash(id, operationState, stateEnteredTime, startTime, nfvoNsInst, operation, isAutoInnovation, + operationParams, isCancelPending); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoNsInst {\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(" isAutoInnovation: ").append(toIndentedString(isAutoInnovation)).append("\n"); + sb.append(" operationParams: ").append(toIndentedString(operationParams)).append("\n"); + sb.append(" isCancelPending: ").append(toIndentedString(isCancelPending)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/so-etsi-nfvo/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/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 0000000000..351f9611c5 --- /dev/null +++ b/so-etsi-nfvo/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/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/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 0000000000..236652e027 --- /dev/null +++ b/so-etsi-nfvo/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/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/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 0000000000..08dbef3866 --- /dev/null +++ b/so-etsi-nfvo/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, INSTANTIATED; + +} diff --git a/so-etsi-nfvo/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/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 0000000000..c55ef5728e --- /dev/null +++ b/so-etsi-nfvo/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,58 @@ +/*- + * ============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.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/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/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 0000000000..0438a4258c --- /dev/null +++ b/so-etsi-nfvo/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,86 @@ +/*- + * ============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 javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +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 { + + @Autowired(required = false) + private MBeanExporter mBeanExporter; + + private static final String NFVO_DATA_SOURCE_QUALIFIER = "nfvoDataSource"; + + @Bean + @ConfigurationProperties(prefix = "spring.datasource.hikari.nfvo") + public HikariConfig nfvoDbConfig() { + return new HikariConfig(); + } + + @Bean(name = NFVO_DATA_SOURCE_QUALIFIER) + public DataSource dataSource() { + if (mBeanExporter != null) { + mBeanExporter.addExcludedBean(NFVO_DATA_SOURCE_QUALIFIER); + } + 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("nfvo") + .build(); + } + + @Primary + @Bean(name = "transactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("entityManagerFactory") final EntityManagerFactory entityManagerFactory) { + return new JpaTransactionManager(entityManagerFactory); + } + +} |