aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/Application.java22
-rw-r--r--src/main/java/org/onap/clamp/dao/LoopLogRepository.java33
-rw-r--r--src/main/java/org/onap/clamp/dao/LoopsRepository.java33
-rw-r--r--src/main/java/org/onap/clamp/dao/MicroServicePolicyRepository.java33
-rw-r--r--src/main/java/org/onap/clamp/dao/OperationalPolicyRepository.java33
-rw-r--r--src/main/java/org/onap/clamp/dao/model/LogType.java28
-rw-r--r--src/main/java/org/onap/clamp/dao/model/Loop.java199
-rw-r--r--src/main/java/org/onap/clamp/dao/model/LoopLog.java113
-rw-r--r--src/main/java/org/onap/clamp/dao/model/LoopState.java28
-rw-r--r--src/main/java/org/onap/clamp/dao/model/MicroServicePolicy.java126
-rw-r--r--src/main/java/org/onap/clamp/dao/model/OperationalPolicy.java90
-rw-r--r--src/main/resources/application-noaaf.properties18
-rw-r--r--src/main/resources/application.properties14
-rw-r--r--src/test/java/org/onap/clamp/it/dao/model/LoopItCase.java98
-rw-r--r--src/test/resources/application.properties17
15 files changed, 872 insertions, 13 deletions
diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java
index 749a2f6fa..920b0f28c 100644
--- a/src/main/java/org/onap/clamp/clds/Application.java
+++ b/src/main/java/org/onap/clamp/clds/Application.java
@@ -37,9 +37,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
-import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -50,18 +49,18 @@ import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
-
+import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
-@ComponentScan(basePackages = {
- "org.onap.clamp.clds"
-})
-@EnableAutoConfiguration(exclude = {
- DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class,
- SecurityAutoConfiguration.class,UserDetailsServiceAutoConfiguration .class
-})
+@ComponentScan(basePackages = { "org.onap.clamp" })
+@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class,
+ UserDetailsServiceAutoConfiguration.class })
+@EnableJpaRepositories(basePackages = { "org.onap.clamp" })
+@EntityScan(basePackages = { "org.onap.clamp" })
+@EnableTransactionManagement
@EnableConfigurationProperties
@EnableAsync
@EnableScheduling
@@ -106,7 +105,8 @@ public class Application extends SpringBootServletInitializer {
*/
@Bean
public ServletRegistrationBean camelServletRegistrationBean() throws IOException {
- eelfLogger.info(ResourceFileUtil.getResourceAsString("boot-message.txt")+"(v"+ ClampVersioning.getCldsVersionFromProps()+")"+System.getProperty("line.separator"));
+ eelfLogger.info(ResourceFileUtil.getResourceAsString("boot-message.txt") + "(v"
+ + ClampVersioning.getCldsVersionFromProps() + ")" + System.getProperty("line.separator"));
ServletRegistrationBean registration = new ServletRegistrationBean(new ClampServlet(),
"/restservices/clds/v1/*");
registration.setName("CamelServlet");
diff --git a/src/main/java/org/onap/clamp/dao/LoopLogRepository.java b/src/main/java/org/onap/clamp/dao/LoopLogRepository.java
new file mode 100644
index 000000000..5f983b2aa
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/LoopLogRepository.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao;
+
+import org.onap.clamp.dao.model.LoopLog;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface LoopLogRepository extends CrudRepository<LoopLog, String> {
+
+}
diff --git a/src/main/java/org/onap/clamp/dao/LoopsRepository.java b/src/main/java/org/onap/clamp/dao/LoopsRepository.java
new file mode 100644
index 000000000..51019baac
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/LoopsRepository.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao;
+
+import org.onap.clamp.dao.model.Loop;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface LoopsRepository extends CrudRepository<Loop, String> {
+
+}
diff --git a/src/main/java/org/onap/clamp/dao/MicroServicePolicyRepository.java b/src/main/java/org/onap/clamp/dao/MicroServicePolicyRepository.java
new file mode 100644
index 000000000..1bdaf3e5e
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/MicroServicePolicyRepository.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao;
+
+import org.onap.clamp.dao.model.MicroServicePolicy;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface MicroServicePolicyRepository extends CrudRepository<MicroServicePolicy, String> {
+
+}
diff --git a/src/main/java/org/onap/clamp/dao/OperationalPolicyRepository.java b/src/main/java/org/onap/clamp/dao/OperationalPolicyRepository.java
new file mode 100644
index 000000000..cf03a812e
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/OperationalPolicyRepository.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao;
+
+import org.onap.clamp.dao.model.OperationalPolicy;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface OperationalPolicyRepository extends CrudRepository<OperationalPolicy, String> {
+
+}
diff --git a/src/main/java/org/onap/clamp/dao/model/LogType.java b/src/main/java/org/onap/clamp/dao/model/LogType.java
new file mode 100644
index 000000000..1a8ed36cd
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/model/LogType.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao.model;
+
+public enum LogType {
+ INFO, WARNING, ERROR;
+}
diff --git a/src/main/java/org/onap/clamp/dao/model/Loop.java b/src/main/java/org/onap/clamp/dao/model/Loop.java
new file mode 100644
index 000000000..3473b54ff
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/model/Loop.java
@@ -0,0 +1,199 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao.model;
+
+import com.google.gson.annotations.Expose;
+import com.vladmihalcea.hibernate.type.json.JsonStringType;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+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.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+
+@Entity
+@Table(name = "loops")
+//@JsonAdapter(JsonLoopAdapter.class)
+@TypeDef(name = "json", typeClass = JsonStringType.class)
+public class Loop implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -286522707701388642L;
+
+ @Id
+ @Expose
+ @Column(nullable = false, name = "name", unique = true)
+ private String name;
+
+ @Expose
+ @Column(name = "dcae_deployment_id")
+ private String dcaeDeploymentId;
+
+ @Expose
+ @Column(name = "dcae_deployment_status_url")
+ private String dcaeDeploymentStatusUrl;
+
+ @Expose
+ @Column(name = "svg_representation")
+ private String svgRepresentation;
+
+ @Expose
+ @Type(type = "json")
+ @Column(columnDefinition = "json", name = "global_properties_json")
+ private Map<String, Object> globalPropertiesJson;
+
+ @Expose
+ @Column(nullable = false, name = "blueprint_yaml")
+ private String blueprint;
+
+ @Expose
+ @Column(nullable = false, name = "last_computed_state")
+ @Enumerated(EnumType.STRING)
+ private LoopState lastComputedState;
+
+ @Expose
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
+ private Set<OperationalPolicy> operationalPolicies = new HashSet<>();
+
+ @Expose
+ @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
+ private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
+
+ @Expose
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
+ private Set<LoopLog> loopLogs = new HashSet<>();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDcaeDeploymentId() {
+ return dcaeDeploymentId;
+ }
+
+ public void setDcaeDeploymentId(String dcaeDeploymentId) {
+ this.dcaeDeploymentId = dcaeDeploymentId;
+ }
+
+ public String getDcaeDeploymentStatusUrl() {
+ return dcaeDeploymentStatusUrl;
+ }
+
+ public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
+ this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
+ }
+
+ public String getSvgRepresentation() {
+ return svgRepresentation;
+ }
+
+ public void setSvgRepresentation(String svgRepresentation) {
+ this.svgRepresentation = svgRepresentation;
+ }
+
+ public String getBlueprint() {
+ return blueprint;
+ }
+
+ public void setBlueprint(String blueprint) {
+ this.blueprint = blueprint;
+ }
+
+ public LoopState getLastComputedState() {
+ return lastComputedState;
+ }
+
+ public void setLastComputedState(LoopState lastComputedState) {
+ this.lastComputedState = lastComputedState;
+ }
+
+ public Set<OperationalPolicy> getOperationalPolicies() {
+ return operationalPolicies;
+ }
+
+ public void setOperationalPolicies(Set<OperationalPolicy> operationalPolicies) {
+ this.operationalPolicies = operationalPolicies;
+ }
+
+ public Set<MicroServicePolicy> getMicroServicePolicies() {
+ return microServicePolicies;
+ }
+
+ public void setMicroServicePolicies(Set<MicroServicePolicy> microServicePolicies) {
+ this.microServicePolicies = microServicePolicies;
+ }
+
+ public Map<String, Object> getGlobalPropertiesJson() {
+ return globalPropertiesJson;
+ }
+
+ public void setGlobalPropertiesJson(Map<String, Object> globalPropertiesJson) {
+ this.globalPropertiesJson = globalPropertiesJson;
+ }
+
+ public Set<LoopLog> getLoopLogs() {
+ return loopLogs;
+ }
+
+ public void setLoopLogs(Set<LoopLog> loopLogs) {
+ this.loopLogs = loopLogs;
+ }
+
+ public void addOperationalPolicy(OperationalPolicy opPolicy) {
+ opPolicy.setLoop(this);
+ operationalPolicies.add(opPolicy);
+ }
+
+ public void addMicroServicePolicy(MicroServicePolicy microServicePolicy) {
+ microServicePolicies.add(microServicePolicy);
+ microServicePolicy.getUsedByLoops().add(this);
+ }
+
+ public void addLog(LoopLog log) {
+ loopLogs.add(log);
+ log.setLoop(this);
+ }
+}
diff --git a/src/main/java/org/onap/clamp/dao/model/LoopLog.java b/src/main/java/org/onap/clamp/dao/model/LoopLog.java
new file mode 100644
index 000000000..8f7fd68b2
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/model/LoopLog.java
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao.model;
+
+import com.google.gson.annotations.Expose;
+
+import java.io.Serializable;
+import java.time.Instant;
+
+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 = "loop_logs")
+public class LoopLog implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1988276670074437631L;
+
+ @Expose
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private long id;
+
+ @Expose
+ @Column(name = "log_type", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private LogType logType;
+
+ @Expose
+ @Column(name = "message", nullable = false)
+ private String message;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "loop_id", nullable = false)
+ private Loop loop;
+
+ @Expose
+ @Column(name = "log_instant", nullable = false)
+ private Instant logInstant = Instant.now();
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public LogType getLogType() {
+ return logType;
+ }
+
+ public void setLogType(LogType logType) {
+ this.logType = logType;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Loop getLoop() {
+ return loop;
+ }
+
+ public void setLoop(Loop loop) {
+ this.loop = loop;
+ }
+
+ public Instant getLogInstant() {
+ return logInstant;
+ }
+
+ public void setLogInstant(Instant logInstant) {
+ this.logInstant = logInstant;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/dao/model/LoopState.java b/src/main/java/org/onap/clamp/dao/model/LoopState.java
new file mode 100644
index 000000000..1cde0aa9e
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/model/LoopState.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao.model;
+
+public enum LoopState {
+ DESIGN, SUBMITTED, DEPLOYED, RUNNING, STOPPED, IN_ERROR, WAITING;
+}
diff --git a/src/main/java/org/onap/clamp/dao/model/MicroServicePolicy.java b/src/main/java/org/onap/clamp/dao/model/MicroServicePolicy.java
new file mode 100644
index 000000000..7fa4a55d9
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/model/MicroServicePolicy.java
@@ -0,0 +1,126 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao.model;
+
+import com.google.gson.annotations.Expose;
+import com.vladmihalcea.hibernate.type.json.JsonStringType;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+
+@Entity
+@Table(name = "micro_service_policies")
+@TypeDef(name = "json", typeClass = JsonStringType.class)
+public class MicroServicePolicy implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6271238288583332616L;
+
+ @Expose
+ @Id
+ @Column(nullable = false, name = "name", unique = true)
+ private String name;
+
+ @Expose
+ @Type(type = "json")
+ @Column(columnDefinition = "json", name = "properties")
+ private Map<String, Object> properties;
+
+ @Expose
+ @Column(name = "shared", nullable = false)
+ private Boolean shared;
+
+ @Expose
+ @Column(name = "policy_tosca", nullable = false)
+ private String policyTosca;
+
+ @Expose
+ @Type(type = "json")
+ @Column(columnDefinition = "json", name = "json_representation", nullable = false)
+ private Map<String, Object> jsonRepresentation;
+
+ @ManyToMany(mappedBy = "microServicePolicies")
+ private Set<Loop> usedByLoops = new HashSet<>();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+ public Boolean getShared() {
+ return shared;
+ }
+
+ public void setShared(Boolean shared) {
+ this.shared = shared;
+ }
+
+ public String getPolicyTosca() {
+ return policyTosca;
+ }
+
+ public void setPolicyTosca(String policyTosca) {
+ this.policyTosca = policyTosca;
+ }
+
+ public Map<String, Object> getJsonRepresentation() {
+ return jsonRepresentation;
+ }
+
+ public void setJsonRepresentation(Map<String, Object> jsonRepresentation) {
+ this.jsonRepresentation = jsonRepresentation;
+ }
+
+ public Set<Loop> getUsedByLoops() {
+ return usedByLoops;
+ }
+
+ public void setUsedByLoops(Set<Loop> usedBy) {
+ this.usedByLoops = usedBy;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/dao/model/OperationalPolicy.java b/src/main/java/org/onap/clamp/dao/model/OperationalPolicy.java
new file mode 100644
index 000000000..d66fd9408
--- /dev/null
+++ b/src/main/java/org/onap/clamp/dao/model/OperationalPolicy.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.dao.model;
+
+import com.google.gson.annotations.Expose;
+import com.vladmihalcea.hibernate.type.json.JsonStringType;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+
+@Entity
+@Table(name = "operational_policies")
+@TypeDef(name = "json", typeClass = JsonStringType.class)
+public class OperationalPolicy implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6117076450841538255L;
+
+ @Expose
+ @Id
+ @Column(nullable = false, name = "name", unique = true)
+ private String name;
+
+ @Expose
+ @Type(type = "json")
+ @Column(columnDefinition = "json", name = "configurations_json")
+ private Map<String, Object> configurationsJson;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "loop_id", nullable = false)
+ private Loop loop;
+
+ public Loop getLoop() {
+ return loop;
+ }
+
+ public void setLoop(Loop loop) {
+ this.loop = loop;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Map<String, Object> getConfigurationsJson() {
+ return configurationsJson;
+ }
+
+ public void setConfigurationsJson(Map<String, Object> configurationsJson) {
+ this.configurationsJson = configurationsJson;
+ }
+
+}
diff --git a/src/main/resources/application-noaaf.properties b/src/main/resources/application-noaaf.properties
index 4dbcd4592..7dd0314a1 100644
--- a/src/main/resources/application-noaaf.properties
+++ b/src/main/resources/application-noaaf.properties
@@ -56,6 +56,7 @@ server.port=8080
server.servlet.context-path=/
#Modified engine-rest applicationpath
spring.profiles.active=clamp-default,clamp-default-user,clamp-sdc-controller
+spring.http.converters.preferred-json-mapper=gson
#The max number of active threads in this pool
server.tomcat.max-threads=200
@@ -94,6 +95,22 @@ spring.datasource.cldsdb.initialSize=0
# Automatically test whether a connection provided is good or not
spring.datasource.cldsdb.testOnBorrow=true
spring.datasource.cldsdb.ignoreExceptionOnPreLoad=true
+# control the sql db initialization (from schema.sql and data.sql)
+spring.datasource.initialize=false
+
+spring.jpa.properties.javax.persistence.schema-generation.database.action=none
+s#pring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
+#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
+#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql
+# disable Hibernate DDL generation because the schema will be generated from a sql script
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
+spring.jpa.properties.hibernate.ddl-auto=validate
+spring.jpa.properties.hibernate.hbm2ddl.delimiter=;
+spring.jpa.properties.hibernate.format_sql=true
+spring.jpa.properties.hibernate.use-new-id-generator-mappings=true
+
+# Whether to enable logging of SQL statements.
+spring.jpa.show-sql=true
#Async Executor default Parameters
async.core.pool.size=10
@@ -166,7 +183,6 @@ clamp.config.op.controller=amsterdam
clamp.config.op.policy.appc=APPC
#
# Sdc service properties
-#
clamp.config.sdc.csarFolder = /tmp/sdc-controllers
clamp.config.sdc.blueprint.parser.mapping = classpath:/clds/blueprint-parser-mapping.json
#
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 9852dc8c8..8859c4b32 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -113,6 +113,20 @@ spring.datasource.cldsdb.initialSize=0
spring.datasource.cldsdb.testOnBorrow=true
spring.datasource.cldsdb.ignoreExceptionOnPreLoad=true
+spring.jpa.properties.javax.persistence.schema-generation.database.action=none
+#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
+#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
+#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql
+# disable Hibernate DDL generation because the schema will be generated from a sql script
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
+spring.jpa.properties.hibernate.ddl-auto=validate
+spring.jpa.properties.hibernate.hbm2ddl.delimiter=;
+spring.jpa.properties.hibernate.format_sql=true
+spring.jpa.properties.hibernate.use-new-id-generator-mappings=true
+
+# Whether to enable logging of SQL statements.
+spring.jpa.show-sql=true
+
#Async Executor default Parameters
async.core.pool.size=10
async.max.pool.size=20
diff --git a/src/test/java/org/onap/clamp/it/dao/model/LoopItCase.java b/src/test/java/org/onap/clamp/it/dao/model/LoopItCase.java
new file mode 100644
index 000000000..06f4a7f88
--- /dev/null
+++ b/src/test/java/org/onap/clamp/it/dao/model/LoopItCase.java
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.it.dao.model;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.clamp.clds.Application;
+import org.onap.clamp.dao.LoopsRepository;
+import org.onap.clamp.dao.model.LogType;
+import org.onap.clamp.dao.model.Loop;
+import org.onap.clamp.dao.model.LoopLog;
+import org.onap.clamp.dao.model.LoopState;
+import org.onap.clamp.dao.model.MicroServicePolicy;
+import org.onap.clamp.dao.model.OperationalPolicy;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest(classes = Application.class)
+public class LoopItCase {
+
+ @Autowired
+ private LoopsRepository loopRepository;
+
+ @Test
+ public void DecodeEncodeTest() {
+ Loop loopTest = new Loop();
+ loopTest.setName("ClosedLoopTest");
+ loopTest.setSvgRepresentation("representation");
+ loopTest.setBlueprint("blueprint");
+ loopTest.setGlobalPropertiesJson(new Gson().fromJson("{\"testName\":\"testValue\"}", Map.class));
+ loopTest.setLastComputedState(LoopState.DESIGN);
+ loopTest.setBlueprint("yaml");
+
+ OperationalPolicy opPolicy = new OperationalPolicy();
+ opPolicy.setName("OpPolicyTest");
+ opPolicy.setConfigurationsJson(new Gson().fromJson("{\"testname\":\"testvalue\"}", Map.class));
+ opPolicy.setLoop(loopTest);
+ loopTest.addOperationalPolicy(opPolicy);
+
+ MicroServicePolicy µService = new MicroServicePolicy();
+ µService.setJsonRepresentation(new Gson().fromJson("{\"testrepresentation\":\"value\"}", Map.class));
+ µService.setPolicyTosca("tosca");
+ µService.setProperties(new Gson().fromJson("{\"testparam\":\"testvalue\"}", Map.class));
+ µService.setShared(true);
+
+ µService.setName("ConfigPolicyTest");
+ loopTest.addMicroServicePolicy(µService);
+
+ LoopLog log = new LoopLog();
+ log.setLogType(LogType.INFO);
+ log.setMessage("test message");
+
+ loopTest.addLog(log);
+
+ Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();
+ String json = gson.toJson(loopTest);
+ assertNotNull(json);
+ Loop loopTestDecoded = gson.fromJson(json, Loop.class);
+ assertNotNull(loopTestDecoded);
+ Loop loop = gson.fromJson(json, Loop.class);
+ assertNotNull(loop);
+
+ Loop loopInDb = loopRepository.save(loopTest);
+ assertNotNull(loopInDb);
+ assertTrue(loopRepository.findById(loopInDb.getName()).get().getName().equals("ClosedLoopTest"));
+ }
+}
diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties
index f41b68dfb..16331ba08 100644
--- a/src/test/resources/application.properties
+++ b/src/test/resources/application.properties
@@ -63,6 +63,7 @@ server.port=${clamp.it.tests.http}
server.servlet.context-path=/
#Modified engine-rest applicationpath
spring.profiles.active=clamp-default,clamp-default-user,clamp-sdc-controller
+spring.http.converters.preferred-json-mapper=gson
#The max number of active threads in this pool
server.tomcat.max-threads=200
@@ -90,7 +91,7 @@ camel.springboot.xmlRests=classpath:/clds/camel/rest/*.xml
#clds datasource connection details
spring.datasource.cldsdb.driverClassName=org.mariadb.jdbc.Driver
-spring.datasource.cldsdb.url=jdbc:mariadb:sequential://localhost:${docker.mariadb.port.host}/cldsdb4?autoReconnect=true&connectTimeout=10000&socketTimeout=10000&retriesAllDown=3
+spring.datasource.cldsdb.url=jdbc:mariadb:sequential://localhost:3306,localhost:${docker.mariadb.port.host}/cldsdb4?autoReconnect=true&connectTimeout=10000&socketTimeout=10000&retriesAllDown=3
spring.datasource.cldsdb.username=clds
spring.datasource.cldsdb.password=4c90a0b48204383f4283448d23e0b885a47237b2a23588e7c4651604f51c1067
spring.datasource.cldsdb.validationQuery=SELECT 1
@@ -103,6 +104,20 @@ spring.datasource.cldsdb.initialSize=0
spring.datasource.cldsdb.testOnBorrow=true
spring.datasource.cldsdb.ignoreExceptionOnPreLoad=true
+spring.jpa.properties.javax.persistence.schema-generation.database.action=none
+#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
+#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
+#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql
+# disable Hibernate DDL generation because the schema will be generated from a sql script
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
+spring.jpa.properties.hibernate.ddl-auto=validate
+spring.jpa.properties.hibernate.hbm2ddl.delimiter=;
+spring.jpa.properties.hibernate.format_sql=true
+spring.jpa.properties.hibernate.use-new-id-generator-mappings=true
+
+# Whether to enable logging of SQL statements.
+spring.jpa.show-sql=true
+
#Async Executor default Parameters
async.core.pool.size=10
async.max.pool.size=20