From c4e03f8a933ce35044597ec44d40848cf7957bf5 Mon Sep 17 00:00:00 2001 From: "Smokowski, Steve (ss835w)" Date: Tue, 14 Aug 2018 16:30:49 -0400 Subject: Cloud Config Updates Update Cloud Config to be writable over REST API. This allows easier environment setup, so sql scripts are not required Issue-ID: SO-862 Change-Id: I70931f09ff2600a15094199f46fc8d9ac36403f4 Change-Id: I70931f09ff2600a15094199f46fc8d9ac36403f4 Signed-off-by: Smokowski, Steve (ss835w) --- .../catalogdb/catalogrest/CloudConfigTest.java | 122 ++++++ .../onap/so/adapters/vnf/BaseRestTestUtils.java | 3 - bpmn/mso-infrastructure-bpmn/pom.xml | 5 + .../onap/so/db/catalog/beans/CloudIdentity.java | 1 - .../org/onap/so/db/catalog/beans/CloudSite.java | 416 +++++++++++---------- .../data/repository/CloudIdentityRepository.java | 10 - .../repository/CloudIdentityRepositoryTest.java | 21 -- 7 files changed, 336 insertions(+), 242 deletions(-) create mode 100644 adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CloudConfigTest.java delete mode 100644 mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/CloudIdentityRepository.java delete mode 100644 mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/CloudIdentityRepositoryTest.java diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CloudConfigTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CloudConfigTest.java new file mode 100644 index 0000000000..9ed61b33a3 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CloudConfigTest.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.so.adapters.catalogdb.catalogrest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.net.URI; +import java.util.List; + +import javax.transaction.Transactional; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.catalogdb.CatalogDBApplication; +import org.onap.so.db.catalog.beans.AuthenticationType; +import org.onap.so.db.catalog.beans.BuildingBlockDetail; +import org.onap.so.db.catalog.beans.CloudIdentity; +import org.onap.so.db.catalog.beans.CloudSite; +import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; +import org.onap.so.db.catalog.beans.CollectionResourceCustomization; +import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; +import org.onap.so.db.catalog.beans.InstanceGroup; +import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; +import org.onap.so.db.catalog.beans.ServerType; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.logger.MsoLogger; +import org.onap.so.logging.jaxrs.filter.jersey.SpringClientFilter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.util.UriComponentsBuilder; +import uk.co.blackpepper.bowman.Client; +import uk.co.blackpepper.bowman.ClientFactory; +import uk.co.blackpepper.bowman.Configuration; +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class CloudConfigTest { + + protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); + + protected HttpHeaders headers = new HttpHeaders(); + + @LocalServerPort + private int port; + + @Test + @Transactional + public void createCloudSiteRest_TEST() { + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type",MediaType.APPLICATION_JSON); + + CloudSite cloudSite = new CloudSite(); + cloudSite.setId("MTN6"); + cloudSite.setClli("TESTCLLI"); + cloudSite.setRegionId("regionId"); + cloudSite.setCloudVersion("VERSION"); + cloudSite.setPlatform("PLATFORM"); + + CloudIdentity cloudIdentity = new CloudIdentity(); + cloudIdentity.setId("RANDOMID"); + cloudIdentity.setIdentityUrl("URL"); + cloudIdentity.setMsoId("MSO_ID"); + cloudIdentity.setMsoPass("MSO_PASS"); + cloudIdentity.setAdminTenant("ADMIN_TENANT"); + cloudIdentity.setMemberRole("ROLE"); + cloudIdentity.setIdentityServerType(ServerType.KEYSTONE); + cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY); + cloudSite.setIdentityService(cloudIdentity); + String uri = "/cloudSite"; + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri); + HttpEntity request = new HttpEntity(cloudSite, headers); + ResponseEntity response = restTemplate.exchange(builder.toUriString(), + HttpMethod.POST, request, String.class); + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value()); + + builder = UriComponentsBuilder.fromHttpUrl("http://localhost:"+ port + uri +"/" + cloudSite.getId()); + HttpEntity entity = new HttpEntity(null, headers); + ResponseEntity actualCloudSite = restTemplate.exchange(builder.toUriString(),HttpMethod.GET, entity, CloudSite.class); + + assertEquals(Response.Status.OK.getStatusCode(), actualCloudSite.getStatusCode().value()); + assertThat(actualCloudSite.getBody(), sameBeanAs(cloudSite).ignoring("created").ignoring("updated") + .ignoring("identityService.created").ignoring("identityService.updated")); + + } + +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java index cf68f097dc..d2b6d4f633 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java @@ -33,7 +33,6 @@ import org.onap.so.db.catalog.beans.AuthenticationType; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.ServerType; -import org.onap.so.db.catalog.data.repository.CloudIdentityRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -76,8 +75,6 @@ public class BaseRestTestUtils { public ObjectMapper mapper; - @Autowired - private CloudIdentityRepository cloudIdentityRepository; protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{ ObjectMapper mapper = new ObjectMapper(); diff --git a/bpmn/mso-infrastructure-bpmn/pom.xml b/bpmn/mso-infrastructure-bpmn/pom.xml index e44156daa9..151ba2c3aa 100644 --- a/bpmn/mso-infrastructure-bpmn/pom.xml +++ b/bpmn/mso-infrastructure-bpmn/pom.xml @@ -196,5 +196,10 @@ micrometer-registry-prometheus 1.0.5 + + org.onap.so + so-bpmn-tasks + ${project.version} + diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java index e6d02c6836..b1c81cf8d8 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java @@ -23,7 +23,6 @@ package org.onap.so.db.catalog.beans; import com.fasterxml.jackson.annotation.JsonProperty; import com.openpojo.business.annotation.BusinessKey; import org.apache.commons.lang3.builder.HashCodeBuilder; - import java.util.Date; import org.apache.commons.lang3.builder.EqualsBuilder; diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudSite.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudSite.java index 53c97fbce6..9cce212c36 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudSite.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudSite.java @@ -51,211 +51,213 @@ import javax.persistence.TemporalType; @Entity @Table(name = "cloud_sites") public class CloudSite { - - @JsonProperty - @BusinessKey - @Id - @Column(name = "ID") - private String id; - - @JsonProperty("region_id") - @BusinessKey - @Column(name = "REGION_ID") - private String regionId; - - @JsonProperty("aic_version") - @BusinessKey - @Column(name = "CLOUD_VERSION") - private String cloudVersion; - - @JsonProperty("clli") - @BusinessKey - @Column(name = "CLLI") - private String clli; - - @JsonProperty("platform") - @BusinessKey - @Column(name = "PLATFORM") - private String platform; - - @JsonProperty("orchestrator") - @BusinessKey - @Column(name = "ORCHESTRATOR") - private String orchestrator; - - @JsonProperty("cloudify_id") - @BusinessKey - @Column(name = "CLOUDIFY_ID") - private String cloudifyId; - - // Derived property (set by CloudConfig loader based on identityServiceId) - @BusinessKey - @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @JoinColumn(name = "IDENTITY_SERVICE_ID") - private CloudIdentity identityService; - - @BusinessKey - @JsonProperty("identity_service_id") - transient private String identityServiceId; - - @JsonProperty("last_updated_by") - @BusinessKey - @Column(name = "LAST_UPDATED_BY") - private String lastUpdatedBy ; - - @JsonProperty("creation_timestamp") - @BusinessKey - @Column(name = "CREATION_TIMESTAMP", updatable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date created; - - @JsonProperty("update_timestamp") - @BusinessKey - @Column(name = "UPDATE_TIMESTAMP") - @Temporal(TemporalType.TIMESTAMP) - private Date updated; - - public CloudSite() { - - } - - @PrePersist - protected void onCreate() { - this.created = new Date(); - this.updated = new Date(); - } - - public CloudSite(CloudSite site) { - this.cloudVersion = site.getCloudVersion(); - this.clli = site.getClli(); - this.id = site.getId(); - this.identityService = site.getIdentityService(); - this.orchestrator = site.getOrchestrator(); - this.platform = site.getPlatform(); - this.regionId = site.getRegionId(); - this.identityServiceId = site.getIdentityServiceId(); - } - public String getId() { - return this.id; - } - - public void setId(String id) { - this.id = id; - } - - public String getRegionId() { - return regionId; - } - - public void setRegionId(String regionId) { - this.regionId = regionId; - } - - public String getIdentityServiceId() { - return identityServiceId == null ? (identityService== null? null:identityService.getId()):identityServiceId; - } - - public String getCloudVersion() { - return cloudVersion; - } - - public void setCloudVersion(String cloudVersion) { - this.cloudVersion = cloudVersion; - } - - public String getClli() { - return clli; - } - - public void setClli(String clli) { - this.clli = clli; - } - - public String getCloudifyId() { - return cloudifyId; - } - - public void setCloudifyId(String cloudifyId) { - this.cloudifyId = cloudifyId; - } - - public String getLastUpdatedBy() { - return lastUpdatedBy; - } - - public Date getCreated() { - return created; - } - - public Date getUpdated() { - return updated; - } - - public void setLastUpdatedBy(String lastUpdatedBy) { - this.lastUpdatedBy = lastUpdatedBy; - } - - public void setCreated(Date created) { - this.created = created; - } - - public void setUpdated(Date updated) { - this.updated = updated; - } - - public String getPlatform() { - return platform; - } - - public void setPlatform(String platform) { - this.platform = platform; - } - - public String getOrchestrator() { - return orchestrator; - } - - public void setOrchestrator(String orchestrator) { - this.orchestrator = orchestrator; - } - - public CloudIdentity getIdentityService () { - return identityService; - } - - public void setIdentityService (CloudIdentity identity) { - this.identityService = identity; - } - @Deprecated - public void setIdentityServiceId(String identityServiceId) { - this.identityServiceId = identityServiceId; - } - - @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("regionId", getRegionId()) - .append("identityServiceId", getIdentityServiceId()).append("cloudVersion", getCloudVersion()) - .append("clli", getClli()).append("cloudifyId", getCloudifyId()).append("platform", getPlatform()) - .append("orchestrator", getOrchestrator()).toString(); - } - - @Override - public boolean equals(final Object other) { - if (other == null) { - return false; - } - if (!getClass().equals(other.getClass())) { - return false; - } - CloudSite castOther = (CloudSite) other; - return new EqualsBuilder().append(getRegionId(), castOther.getRegionId()) - .append(getIdentityServiceId(), castOther.getIdentityServiceId()) - .append(getCloudVersion(), castOther.getCloudVersion()).append(getClli(), castOther.getClli()).isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(1, 31).append(getRegionId()).append(getIdentityServiceId()).append(getCloudVersion()) - .append(getClli()).toHashCode(); - } + + @JsonProperty + @BusinessKey + @Id + @Column(name = "ID") + private String id; + + @JsonProperty("region_id") + @BusinessKey + @Column(name = "REGION_ID") + private String regionId; + + @JsonProperty("aic_version") + @BusinessKey + @Column(name = "CLOUD_VERSION") + private String cloudVersion; + + @JsonProperty("clli") + @BusinessKey + @Column(name = "CLLI") + private String clli; + + @JsonProperty("platform") + @BusinessKey + @Column(name = "PLATFORM") + private String platform; + + @JsonProperty("orchestrator") + @BusinessKey + @Column(name = "ORCHESTRATOR") + private String orchestrator; + + @JsonProperty("cloudify_id") + @BusinessKey + @Column(name = "CLOUDIFY_ID") + private String cloudifyId; + + // Derived property (set by CloudConfig loader based on identityServiceId) + @BusinessKey + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @JoinColumn(name = "IDENTITY_SERVICE_ID") + private CloudIdentity identityService; + + @BusinessKey + @JsonProperty("identity_service_id") + private transient String identityServiceId; + + @JsonProperty("last_updated_by") + @BusinessKey + @Column(name = "LAST_UPDATED_BY") + private String lastUpdatedBy ; + + @JsonProperty("creation_timestamp") + @BusinessKey + @Column(name = "CREATION_TIMESTAMP", updatable = false) + @Temporal(TemporalType.TIMESTAMP) + private Date created; + + @JsonProperty("update_timestamp") + @BusinessKey + @Column(name = "UPDATE_TIMESTAMP") + @Temporal(TemporalType.TIMESTAMP) + private Date updated; + + public CloudSite() { + + } + + @PrePersist + protected void onCreate() { + this.created = new Date(); + this.updated = new Date(); + } + + public CloudSite(CloudSite site) { + this.cloudVersion = site.getCloudVersion(); + this.clli = site.getClli(); + this.id = site.getId(); + this.identityService = site.getIdentityService(); + this.orchestrator = site.getOrchestrator(); + this.platform = site.getPlatform(); + this.regionId = site.getRegionId(); + this.identityServiceId = site.getIdentityServiceId(); + } + + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getRegionId() { + return regionId; + } + + public void setRegionId(String regionId) { + this.regionId = regionId; + } + + public String getIdentityServiceId() { + return identityServiceId == null ? (identityService== null? null:identityService.getId()):identityServiceId; + } + + public String getCloudVersion() { + return cloudVersion; + } + + public void setCloudVersion(String cloudVersion) { + this.cloudVersion = cloudVersion; + } + + public String getClli() { + return clli; + } + + public void setClli(String clli) { + this.clli = clli; + } + + public String getCloudifyId() { + return cloudifyId; + } + + public void setCloudifyId(String cloudifyId) { + this.cloudifyId = cloudifyId; + } + + public String getLastUpdatedBy() { + return lastUpdatedBy; + } + + public Date getCreated() { + return created; + } + + public Date getUpdated() { + return updated; + } + + public void setLastUpdatedBy(String lastUpdatedBy) { + this.lastUpdatedBy = lastUpdatedBy; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setUpdated(Date updated) { + this.updated = updated; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getOrchestrator() { + return orchestrator; + } + + public void setOrchestrator(String orchestrator) { + this.orchestrator = orchestrator; + } + + public CloudIdentity getIdentityService () { + return identityService; + } + + public void setIdentityService (CloudIdentity identity) { + this.identityService = identity; + } + @Deprecated + public void setIdentityServiceId(String identityServiceId) { + this.identityServiceId = identityServiceId; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("regionId", getRegionId()) + .append("identityServiceId", getIdentityServiceId()).append("cloudVersion", getCloudVersion()) + .append("clli", getClli()).append("cloudifyId", getCloudifyId()).append("platform", getPlatform()) + .append("orchestrator", getOrchestrator()).toString(); + } + + @Override + public boolean equals(final Object other) { + if (other == null) { + return false; + } + if (!getClass().equals(other.getClass())) { + return false; + } + CloudSite castOther = (CloudSite) other; + return new EqualsBuilder().append(getRegionId(), castOther.getRegionId()) + .append(getIdentityServiceId(), castOther.getIdentityServiceId()) + .append(getCloudVersion(), castOther.getCloudVersion()).append(getClli(), castOther.getClli()).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(1, 31).append(getRegionId()).append(getIdentityServiceId()).append(getCloudVersion()) + .append(getClli()).toHashCode(); + } } \ No newline at end of file diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/CloudIdentityRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/CloudIdentityRepository.java deleted file mode 100644 index c1714821ee..0000000000 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/CloudIdentityRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.onap.so.db.catalog.data.repository; - -import org.onap.so.db.catalog.beans.CloudIdentity; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource(collectionResourceRel = "cloudIdentity", path = "cloudIdentity") -public interface CloudIdentityRepository extends JpaRepository { - -} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/CloudIdentityRepositoryTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/CloudIdentityRepositoryTest.java deleted file mode 100644 index 8fb65c2080..0000000000 --- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/CloudIdentityRepositoryTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.onap.so.db.catalog.data.repository; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.so.BaseTest; -import org.onap.so.db.catalog.beans.CloudIdentity; -import org.springframework.beans.factory.annotation.Autowired; - -public class CloudIdentityRepositoryTest extends BaseTest { - - @Autowired - private CloudIdentityRepository cloudIdentityRepository; - - @Test - public void findOneTest() throws Exception { - CloudIdentity cloudIdentity = cloudIdentityRepository.findOne("mtn13"); - Assert.assertNotNull(cloudIdentity); - Assert.assertEquals("mtn13",cloudIdentity.getId()); - } - -} \ No newline at end of file -- cgit 1.2.3-korg