aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/InventoryApplication.java85
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/InventoryConfiguration.java57
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/LinkSerializer.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/clients/DCAEControllerClient.java29
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/clients/DatabusControllerClient.java34
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceComponentsDAO.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTransactionDAO.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypeTransactionDAO.java43
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypesDAO.java82
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesComponentsMapsDAO.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesDAO.java41
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAO.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAOManager.java101
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/dbthings/StringListArgument.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapper.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapper.java29
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java35
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceComponentObject.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceObject.java41
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java81
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerClientException.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerConnectionException.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerTimeoutException.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/exceptions/DatabusControllerClientException.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DBIExceptionMapper.java82
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerConnectionExceptionMapper.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerExceptionMapper.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerTimeoutExceptionMapper.java27
-rw-r--r--src/main/java/org/openecomp/dcae/inventory/providers/NotFoundExceptionMapper.java27
29 files changed, 663 insertions, 509 deletions
diff --git a/src/main/java/org/openecomp/dcae/inventory/InventoryApplication.java b/src/main/java/org/openecomp/dcae/inventory/InventoryApplication.java
index 9a16331..b64a917 100644
--- a/src/main/java/org/openecomp/dcae/inventory/InventoryApplication.java
+++ b/src/main/java/org/openecomp/dcae/inventory/InventoryApplication.java
@@ -1,39 +1,35 @@
-package org.openecomp.dcae.inventory;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory;
+
import org.openecomp.dcae.inventory.clients.DCAEControllerClient;
import org.openecomp.dcae.inventory.clients.DatabusControllerClient;
import org.openecomp.dcae.inventory.daos.InventoryDAOManager;
-import org.openecomp.dcae.inventory.dbthings.StringListArgument;
+import org.openecomp.dcae.inventory.exceptions.mappers.DBIExceptionMapper;
import org.openecomp.dcae.inventory.exceptions.mappers.DCAEControllerConnectionExceptionMapper;
import org.openecomp.dcae.inventory.exceptions.mappers.DCAEControllerTimeoutExceptionMapper;
import org.openecomp.dcae.inventory.providers.NotFoundExceptionMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import io.dropwizard.Application;
import io.dropwizard.client.JerseyClientBuilder;
-import io.dropwizard.jdbi.DBIFactory;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.swagger.api.DcaeServiceTypesApi;
@@ -47,7 +43,6 @@ import io.swagger.models.Contact;
import io.swagger.models.Info;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
-import org.skife.jdbi.v2.DBI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,6 +51,7 @@ import javax.servlet.FilterRegistration;
import javax.ws.rs.client.Client;
import javax.ws.rs.core.Link;
import java.util.EnumSet;
+import java.util.Locale;
/**
@@ -66,6 +62,10 @@ public class InventoryApplication extends Application<InventoryConfiguration> {
static final Logger LOG = LoggerFactory.getLogger(InventoryApplication.class);
public static void main(String[] args) throws Exception {
+ // This is here to try to fix a "high" issue caught by Fortify. Did this **plus** setting locale for each of the
+ // string comparisons that use `toUpper` because of this StackOverflow post:
+ // http://stackoverflow.com/questions/38308777/fixed-fortify-scan-locale-changes-are-reappearing
+ Locale.setDefault(Locale.ENGLISH);
new InventoryApplication().run(args);
}
@@ -79,7 +79,8 @@ public class InventoryApplication extends Application<InventoryConfiguration> {
// This Info object was lifted from the Swagger generated io.swagger.api.Bootstrap file. Although it was not generated
// correctly.
Info info = new Info().title("DCAE Inventory API").version("0.8.0")
- .description("DCAE Inventory is a web service that provides the following:\n\n1. Real-time data on all DCAE services and their components\n2. Comprehensive details on available DCAE service types\n");
+ .description("DCAE Inventory is a web service that provides the following:\n\n1. Real-time data on all DCAE services and their components\n2. Comprehensive details on available DCAE service types\n")
+ .contact(new Contact().email("dcae@lists.openecomp.org"));
// Swagger/servlet/jax-rs magic!
BeanConfig beanConfig = new BeanConfig();
beanConfig.setInfo(info);
@@ -91,10 +92,8 @@ public class InventoryApplication extends Application<InventoryConfiguration> {
public void run(InventoryConfiguration configuration, Environment environment) {
LOG.info("Starting DCAE inventory application");
LOG.info(String.format("DB driver properties: %s", configuration.getDataSourceFactory().getProperties().toString()));
- final DBIFactory factory = new DBIFactory();
- final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "dcae-database");
- jdbi.registerArgumentFactory(new StringListArgument());
- InventoryDAOManager.getInstance().init(jdbi);
+ InventoryDAOManager.getInstance().setup(environment, configuration);
+ InventoryDAOManager.getInstance().initialize();
// Add filter for CORS support for DCAE dashboard
// http://jitterted.com/tidbits/2014/09/12/cors-for-dropwizard-0-7-x/
@@ -113,24 +112,42 @@ public class InventoryApplication extends Application<InventoryConfiguration> {
// Setup DCAE controller client
// Used by the dcae-services API
- final Client clientDCAEController = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration())
- .build("DCAEControllerClient");
- HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder().build();
- clientDCAEController.register(feature);
- final DCAEControllerClient dcaeControllerClient = new DCAEControllerClient(clientDCAEController, configuration.getDcaeControllerConnection());
- DcaeServicesApiServiceFactory.setDcaeControllerClient(dcaeControllerClient);
+ if (configuration.getDcaeControllerConnection().getRequired()) {
+ final Client clientDCAEController = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration())
+ .build("DCAEControllerClient");
+ HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder().build();
+ clientDCAEController.register(feature);
+ final DCAEControllerClient dcaeControllerClient = new DCAEControllerClient(clientDCAEController, configuration.getDcaeControllerConnection());
+ DcaeServicesApiServiceFactory.setDcaeControllerClient(dcaeControllerClient);
+
+ LOG.info("Use of DCAE controller client is required. Turned on.");
+ } else {
+ LOG.warn("Use of DCAE controller client is *not* required. Turned off.");
+ }
// Setup Databus controller client
// Used by the dcae-services API
- final Client clientDatabusController = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration())
- .build("DatabusControllerClient");
- final DatabusControllerClient databusControllerClient = new DatabusControllerClient(clientDatabusController,
- configuration.getDatabusControllerConnection());
- DcaeServicesApiServiceFactory.setDatabusControllerClient(databusControllerClient);
+ if (configuration.getDatabusControllerConnection().getRequired()) {
+ final Client clientDatabusController = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration())
+ .build("DatabusControllerClient");
+ clientDatabusController.register(HttpAuthenticationFeature.basicBuilder().credentials(
+ configuration.getDatabusControllerConnection().getMechId(),
+ configuration.getDatabusControllerConnection().getPassword()).build());
+ final DatabusControllerClient databusControllerClient = new DatabusControllerClient(clientDatabusController,
+ configuration.getDatabusControllerConnection());
+ DcaeServicesApiServiceFactory.setDatabusControllerClient(databusControllerClient);
+
+ LOG.info("Use of databus controller client is required. Turned on.");
+ } else {
+ LOG.warn("Use of databus controller client is *not* required. Turned off.");
+ }
environment.jersey().register(NotFoundExceptionMapper.class);
environment.jersey().register(DCAEControllerConnectionExceptionMapper.class);
environment.jersey().register(DCAEControllerTimeoutExceptionMapper.class);
+ environment.jersey().register(DBIExceptionMapper.UnableToObtainConnectionExceptionMapper.class);
+ environment.jersey().register(DBIExceptionMapper.UnableToExecuteStatementExceptionMapper.class);
+ environment.jersey().register(DBIExceptionMapper.UnableToCreateStatementExceptionMapper.class);
environment.jersey().register(new DcaeServicesApi());
environment.jersey().register(new DcaeServiceTypesApi());
diff --git a/src/main/java/org/openecomp/dcae/inventory/InventoryConfiguration.java b/src/main/java/org/openecomp/dcae/inventory/InventoryConfiguration.java
index 54370ee..55bcca2 100644
--- a/src/main/java/org/openecomp/dcae/inventory/InventoryConfiguration.java
+++ b/src/main/java/org/openecomp/dcae/inventory/InventoryConfiguration.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory;
+
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
import io.dropwizard.client.JerseyClientConfiguration;
@@ -58,6 +55,9 @@ public class InventoryConfiguration extends Configuration {
@JsonProperty
private String password;
+ @JsonProperty
+ private Boolean required = true;
+
public String getHost() {
return this.host;
}
@@ -77,6 +77,10 @@ public class InventoryConfiguration extends Configuration {
public String getPassword() {
return this.password;
}
+
+ public Boolean getRequired() {
+ return this.required;
+ }
}
public static class DatabusControllerConnectionConfiguration {
@@ -88,6 +92,17 @@ public class InventoryConfiguration extends Configuration {
@JsonProperty
private Integer port;
+ @NotNull
+ @JsonProperty
+ private String mechId;
+
+ @NotNull
+ @JsonProperty
+ private String password;
+
+ @JsonProperty
+ private Boolean required = true;
+
public String getHost() {
return host;
}
@@ -95,6 +110,18 @@ public class InventoryConfiguration extends Configuration {
public Integer getPort() {
return port;
}
+
+ public String getMechId() {
+ return mechId;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public Boolean getRequired() {
+ return this.required;
+ }
}
@NotEmpty
diff --git a/src/main/java/org/openecomp/dcae/inventory/LinkSerializer.java b/src/main/java/org/openecomp/dcae/inventory/LinkSerializer.java
index 8cf07db..b83697f 100644
--- a/src/main/java/org/openecomp/dcae/inventory/LinkSerializer.java
+++ b/src/main/java/org/openecomp/dcae/inventory/LinkSerializer.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory;
+
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
diff --git a/src/main/java/org/openecomp/dcae/inventory/clients/DCAEControllerClient.java b/src/main/java/org/openecomp/dcae/inventory/clients/DCAEControllerClient.java
index 23e05fd..adbe8b7 100644
--- a/src/main/java/org/openecomp/dcae/inventory/clients/DCAEControllerClient.java
+++ b/src/main/java/org/openecomp/dcae/inventory/clients/DCAEControllerClient.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.clients;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.clients;
+
import org.openecomp.dcae.inventory.InventoryConfiguration;
import org.openecomp.dcae.inventory.exceptions.DCAEControllerClientException;
import org.openecomp.dcae.inventory.exceptions.DCAEControllerConnectionException;
@@ -171,7 +168,7 @@ public class DCAEControllerClient {
// Apparently the exceptions are wrapped which is not ideal because many different types of errors are embedded
// in single exception. TODO: May want to come back to split up the errors.
// Example:
- // javax.ws.rs.ProcessingException: org.apache.http.conn.ConnectTimeoutException: Connect to aaa.bbb.ccc:9998
+ // javax.ws.rs.ProcessingException: org.apache.http.conn.ConnectTimeoutException: Connect to <dcae controller domain name>:9998
String message = "Connecting with DCAE controller probably timed out";
LOG.error(message, e);
String exceptionMessage = String.format("%s: %s", message, e.getMessage());
diff --git a/src/main/java/org/openecomp/dcae/inventory/clients/DatabusControllerClient.java b/src/main/java/org/openecomp/dcae/inventory/clients/DatabusControllerClient.java
index ac3bbf1..9df11d5 100644
--- a/src/main/java/org/openecomp/dcae/inventory/clients/DatabusControllerClient.java
+++ b/src/main/java/org/openecomp/dcae/inventory/clients/DatabusControllerClient.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.clients;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.clients;
+
import org.openecomp.dcae.inventory.InventoryConfiguration;
import org.openecomp.dcae.inventory.exceptions.DatabusControllerClientException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -51,7 +48,7 @@ public class DatabusControllerClient {
resourcePath = (new StringBuilder("/")).append(resourcePath).toString();
}
- return UriBuilder.fromPath(resourcePath.toString()).scheme("http").host(this.connectionConfiguration.getHost())
+ return UriBuilder.fromPath(resourcePath.toString()).scheme("https").host(this.connectionConfiguration.getHost())
.port(this.connectionConfiguration.getPort()).build();
}
@@ -74,6 +71,11 @@ public class DatabusControllerClient {
} catch (IOException e) {
throw new DatabusControllerClientException(e);
}
+ } else if (response.getStatus() == 401) {
+ // You probably got this because your mech id/password is not authorized
+ throw new DatabusControllerClientException(String.format("Check the mech id/password: %d", response.getStatus()));
+ } else if (response.getStatus() == 403) {
+ throw new DatabusControllerClientException(String.format("Credentials not authorized: %d", response.getStatus()));
}
throw new DatabusControllerClientException(String.format("Unexpected error from databus controller: %d",
diff --git a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceComponentsDAO.java b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceComponentsDAO.java
index d1b5ec0..9a674c9 100644
--- a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceComponentsDAO.java
+++ b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceComponentsDAO.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.daos;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.daos;
+
import org.openecomp.dcae.inventory.dbthings.mappers.DCAEServiceComponentObjectMapper;
import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceComponentObject;
import org.skife.jdbi.v2.sqlobject.Bind;
diff --git a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTransactionDAO.java b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTransactionDAO.java
index dc3d6b3..f0fca86 100644
--- a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTransactionDAO.java
+++ b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTransactionDAO.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.daos;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.daos;
+
import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceComponentObject;
import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceObject;
import org.joda.time.DateTime;
diff --git a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypeTransactionDAO.java b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypeTransactionDAO.java
deleted file mode 100644
index c3c65e2..0000000
--- a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypeTransactionDAO.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.openecomp.dcae.inventory.daos;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
- */
-
-import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceTypeObject;
-import org.skife.jdbi.v2.sqlobject.CreateSqlObject;
-
-/**
- * Created by mhwang on 5/19/16.
- */
-public abstract class DCAEServiceTypeTransactionDAO {
-
- @CreateSqlObject
- abstract DCAEServiceTypesDAO getServiceTypesDAO();
-
- public void upsert(DCAEServiceTypeObject newerVersion) {
- // Order of operation is important here!
- this.getServiceTypesDAO().deactivateExisting(newerVersion.getTypeName());
- this.getServiceTypesDAO().insertNewerVersion(newerVersion);
- }
-
-}
diff --git a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypesDAO.java b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypesDAO.java
index 5c961f9..50b79b2 100644
--- a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypesDAO.java
+++ b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTypesDAO.java
@@ -1,30 +1,29 @@
-package org.openecomp.dcae.inventory.daos;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.daos;
+
import org.openecomp.dcae.inventory.dbthings.mappers.DCAEServiceTypeObjectMapper;
+
import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceTypeObject;
+import io.swagger.model.DCAEServiceTypeRequest;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
@@ -32,10 +31,9 @@ import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.customizers.Mapper;
/**
- * DCAE service type records are treated immutable. Newer versions are added with the flag "is_active" set to TRUE.
- * The responsibility of managing the active version on the caller of this DAO.
- *
- * Currently the "is_active" flag is hidden to the application except in this DAO.
+ * DCAE service type records are no longer treated immutable because versioning is handled by clients
+ * to DCAE inventory i.e. ASDC. There is field "deactivated" that determines if a service type is active.
+ * Inserts and updates automatically activates a service type while deleting deactivates a service type.
*
* Created by mhwang on 4/19/16.
*/
@@ -48,21 +46,45 @@ public interface DCAEServiceTypesDAO extends InventoryDAO {
* Note that service_ids and service_locations are nullable fields. This might not be the right decision but because
* the resource model allows for nulls, thought it should consistent.
*/
- @SqlUpdate("create table dcae_service_types (type_name varchar not null, owner varchar not null," +
- "vnf_types varchar[] not null, service_ids varchar[], service_locations varchar[], blueprint_template text not null, " +
- "created timestamp not null, is_active boolean not null, constraint pk_type_created primary key (type_name, created))")
+ @SqlUpdate("create table dcae_service_types (type_id varchar not null, type_version integer not null, " +
+ "type_name varchar not null, owner varchar not null, blueprint_template text not null, " +
+ "vnf_types varchar[] not null, service_ids varchar[], service_locations varchar[], " +
+ "asdc_service_id varchar, asdc_resource_id varchar, " +
+ "created timestamp not null, deactivated timestamp, constraint pk_type_created primary key (type_id))")
void createTable();
- @SqlUpdate("insert into dcae_service_types(type_name, owner, vnf_types, service_ids, service_locations, " +
- "blueprint_template, created, is_active) values (:typeName, :owner, :vnfTypes, :serviceIds, :serviceLocations, " +
- ":blueprintTemplate, :created, TRUE)")
- void insertNewerVersion(@BindBean DCAEServiceTypeObject serviceObject);
+ // REVIEW: asdcServiceId and asdcResourceId is implicitly part of the unique key and thus shouldn't be updated.
+ @SqlUpdate("insert into dcae_service_types(type_id, type_version, type_name, owner, blueprint_template, vnf_types, " +
+ "service_ids, service_locations, asdc_service_id, asdc_resource_id, created, deactivated) " +
+ "values (:typeId, :typeVersion, :typeName, :owner, :blueprintTemplate, :vnfTypes, :serviceIds, " +
+ ":serviceLocations, :asdcServiceId, :asdcResourceId, :created, null)")
+ void insert(@BindBean DCAEServiceTypeObject serviceObject);
+
+ @SqlUpdate("update dcae_service_types set " +
+ "owner = :owner, blueprint_template = :blueprintTemplate, vnf_types = :vnfTypes, " +
+ "service_ids = :serviceIds, service_locations = :serviceLocations, created = :created, " +
+ "deactivated = null where type_id = :typeId")
+ void update(@BindBean DCAEServiceTypeObject serviceObject);
+
+ @SqlUpdate("update dcae_service_types set deactivated = (now() at time zone 'utc') where type_id = :typeId")
+ void deactivateExisting(@Bind("typeId") String typeId);
+
+ @Mapper(DCAEServiceTypeObjectMapper.class)
+ @SqlQuery("select * from dcae_service_types where type_id = :it")
+ DCAEServiceTypeObject getByTypeId(@Bind String typeId);
+
+ @Mapper(DCAEServiceTypeObjectMapper.class)
+ @SqlQuery("select * from dcae_service_types where deactivated is null and type_id = :it")
+ DCAEServiceTypeObject getByTypeIdActiveOnly(@Bind String typeId);
- @SqlUpdate("update dcae_service_types set is_active = FALSE where type_name = :typeName and is_active = TRUE")
- void deactivateExisting(@Bind("typeName") String typeName);
+ @Mapper(DCAEServiceTypeObjectMapper.class)
+ @SqlQuery("select * from dcae_service_types where type_name = :typeName and type_version = :typeVersion " +
+ "and asdc_service_id is null and asdc_resource_id is null")
+ DCAEServiceTypeObject getByRequestFromNotASDC(@BindBean DCAEServiceTypeRequest serviceTypeObject);
@Mapper(DCAEServiceTypeObjectMapper.class)
- @SqlQuery("select * from dcae_service_types where is_active = TRUE and type_name = :it")
- DCAEServiceTypeObject getByTypeName(@Bind String typeName);
+ @SqlQuery("select * from dcae_service_types where type_name = :typeName and type_version = :typeVersion " +
+ "and asdc_service_id = :asdcServiceId and asdc_resource_id = :asdcResourceId")
+ DCAEServiceTypeObject getByRequestFromASDC(@BindBean DCAEServiceTypeRequest serviceTypeObject);
}
diff --git a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesComponentsMapsDAO.java b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesComponentsMapsDAO.java
index 405476d..5bfd3cd 100644
--- a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesComponentsMapsDAO.java
+++ b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesComponentsMapsDAO.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.daos;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.daos;
+
import org.joda.time.DateTime;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
diff --git a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesDAO.java b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesDAO.java
index e40b8b5..9200677 100644
--- a/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesDAO.java
+++ b/src/main/java/org/openecomp/dcae/inventory/daos/DCAEServicesDAO.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.daos;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.daos;
+
import org.openecomp.dcae.inventory.dbthings.mappers.DCAEServiceObjectMapper;
import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceObject;
import org.joda.time.DateTime;
@@ -42,17 +39,17 @@ public interface DCAEServicesDAO extends InventoryDAO {
@SqlQuery("select exists (select * from information_schema.tables where table_name = \'dcae_services\')")
Boolean checkIfTableExists();
- @SqlUpdate("create table dcae_services (service_id varchar not null primary key, type_name varchar not null, " +
+ @SqlUpdate("create table dcae_services (service_id varchar not null primary key, type_id varchar not null, " +
"vnf_id varchar not null, vnf_type varchar not null, vnf_location varchar not null, deployment_ref varchar, " +
"created timestamp not null, modified timestamp not null, status varchar not null)")
void createTable();
- @SqlUpdate("insert into dcae_services(service_id, type_name, vnf_id, vnf_type, vnf_location, deployment_ref, " +
- "created, modified, status) values (:serviceId, :typeName, :vnfId, :vnfType, :vnfLocation, :deploymentRef, " +
+ @SqlUpdate("insert into dcae_services(service_id, type_id, vnf_id, vnf_type, vnf_location, deployment_ref, " +
+ "created, modified, status) values (:serviceId, :typeId, :vnfId, :vnfType, :vnfLocation, :deploymentRef, " +
":created, :modified, :status)")
void insert(@BindBean DCAEServiceObject serviceObject);
- @SqlUpdate("update dcae_services set type_name = :typeName, vnf_id = :vnfId, vnf_type = :vnfType, " +
+ @SqlUpdate("update dcae_services set type_id = :typeId, vnf_id = :vnfId, vnf_type = :vnfType, " +
"vnf_location = :vnfLocation, deployment_ref = :deploymentRef, modified = :modified, status = :status " +
"where service_id = :serviceId")
void update(@BindBean DCAEServiceObject serviceObject);
@@ -71,7 +68,9 @@ public interface DCAEServicesDAO extends InventoryDAO {
@Bind("serviceId") String serviceId);
@Mapper(IntegerMapper.class)
- @SqlQuery("select count(1) from dcae_services where status = :status and type_name = :typeName")
- Integer countByType(@Bind("status") DCAEServiceObject.DCAEServiceStatus status, @Bind("typeName") String typeName);
+ @SqlQuery("select count(1) from dcae_services where status = :status and type_id = :typeId")
+ Integer countByType(@Bind("status") DCAEServiceObject.DCAEServiceStatus status, @Bind("typeId") String typeId);
}
+
+
diff --git a/src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAO.java b/src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAO.java
index 6205d2c..ef2fb8d 100644
--- a/src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAO.java
+++ b/src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAO.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.daos;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.daos;
+
/**
* Created by mhwang on 4/19/16.
*/
diff --git a/src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAOManager.java b/src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAOManager.java
index fd4d2eb..77611b5 100644
--- a/src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAOManager.java
+++ b/src/main/java/org/openecomp/dcae/inventory/daos/InventoryDAOManager.java
@@ -1,30 +1,32 @@
-package org.openecomp.dcae.inventory.daos;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.daos;
+
+import org.openecomp.dcae.inventory.InventoryConfiguration;
+import org.openecomp.dcae.inventory.dbthings.StringListArgument;
+import io.dropwizard.jdbi.DBIFactory;
+import io.dropwizard.setup.Environment;
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.util.BooleanMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,18 +52,54 @@ public final class InventoryDAOManager {
return instance;
}
+ public static class InventoryDAOManagerSetupException extends RuntimeException {
+
+ public InventoryDAOManagerSetupException(String message) {
+ super(message);
+ }
+
+ }
+
private final static Logger LOG = LoggerFactory.getLogger(InventoryDAOManager.class);
// WATCH! Table creation order matters where mapping tables refer to other tables for foreign keys.
private final static List<Class> DAO_CLASSES = Arrays.asList(DCAEServiceTypesDAO.class, DCAEServicesDAO.class,
DCAEServiceComponentsDAO.class, DCAEServicesComponentsMapsDAO.class);
private DBI jdbi;
+ private Environment environment;
+ private InventoryConfiguration configuration;
private InventoryDAOManager() {
}
- public void init(DBI jdbi) {
- this.jdbi = jdbi;
+ /**
+ * Setup the manager
+ *
+ * Saving the Dropwizard environment and configuration which are used to construct the DBI object in a later
+ * initialize call. This method can only be called once to be safe and to avoid runtime problems that could be
+ * caused if the global instance of this class gets into a weird state (Couldn't use Java's `final` qualifier).
+ *
+ * @param environment
+ * @param inventoryConfiguration
+ */
+ public void setup(Environment environment, InventoryConfiguration inventoryConfiguration) {
+ if (this.environment == null && this.configuration == null) {
+ this.environment = environment;
+ this.configuration = inventoryConfiguration;
+ } else {
+ throw new InventoryDAOManagerSetupException("InventoryDAOManager setup can only be called once.");
+ }
+ }
+
+ /**
+ * Initialize the manager
+ *
+ * Create the underlying validated DBI object that is used to manage database connections
+ */
+ public void initialize() {
+ final DBIFactory factory = new DBIFactory();
+ final DBI jdbi = factory.build(this.environment, this.configuration.getDataSourceFactory(), "dcae-database");
+ jdbi.registerArgumentFactory(new StringListArgument());
for (Class<? extends InventoryDAO> daoClass : DAO_CLASSES) {
final InventoryDAO dao = jdbi.onDemand(daoClass);
@@ -73,6 +111,31 @@ public final class InventoryDAOManager {
LOG.info(String.format("Sql table created: %s", daoClass.getSimpleName()));
}
}
+
+ // CREATE VIEWS
+ // TODO: This doesn't belong here and is not consistent with the above approach. Make it better.
+ try (Handle jdbiHandle = jdbi.open()) {
+ String viewName = "dcae_service_types_latest";
+ String checkQuery = String.format("select exists (select * from information_schema.tables where table_name = '%s')",
+ viewName);
+
+ if (jdbiHandle.createQuery(checkQuery).map(BooleanMapper.FIRST).first()) {
+ LOG.info(String.format("Sql view exists: %s", viewName));
+ } else {
+ StringBuilder sb = new StringBuilder(String.format("create view %s as ", viewName));
+ sb.append("select s.* from dcae_service_types s ");
+ sb.append("join (select type_name, max(type_version) as max_version from dcae_service_types group by type_name) as f ");
+ sb.append("on s.type_name = f.type_name and s.type_version = f.max_version");
+
+ jdbiHandle.execute(sb.toString());
+ LOG.info(String.format("Sql view created: %s", viewName));
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("", e);
+ }
+
+ // Do this assignment at the end after performing table checks to ensure that connection is good
+ this.jdbi = jdbi;
}
private InventoryDAO getDAO(Class<? extends InventoryDAO> klass) {
@@ -102,10 +165,6 @@ public final class InventoryDAOManager {
return jdbi.onDemand(DCAEServiceTransactionDAO.class);
}
- public DCAEServiceTypeTransactionDAO getDCAEServiceTypeTransactionDAO() {
- return jdbi.onDemand(DCAEServiceTypeTransactionDAO.class);
- }
-
public DCAEServiceTypesDAO getDCAEServiceTypesDAO() {
return (DCAEServiceTypesDAO) this.getDAO(DCAEServiceTypesDAO.class);
}
diff --git a/src/main/java/org/openecomp/dcae/inventory/dbthings/StringListArgument.java b/src/main/java/org/openecomp/dcae/inventory/dbthings/StringListArgument.java
index 11c77fd..afd0e78 100644
--- a/src/main/java/org/openecomp/dcae/inventory/dbthings/StringListArgument.java
+++ b/src/main/java/org/openecomp/dcae/inventory/dbthings/StringListArgument.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.dbthings;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.dbthings;
+
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.Argument;
import org.skife.jdbi.v2.tweak.ArgumentFactory;
diff --git a/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapper.java b/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapper.java
index ee0602f..23b42b1 100644
--- a/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapper.java
+++ b/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapper.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.dbthings.mappers;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.dbthings.mappers;
+
import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceComponentObject;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.StatementContext;
diff --git a/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapper.java b/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapper.java
index 7cff043..27cb22f 100644
--- a/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapper.java
+++ b/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapper.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.dbthings.mappers;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.dbthings.mappers;
+
import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceObject;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.StatementContext;
@@ -40,7 +37,7 @@ public class DCAEServiceObjectMapper implements ResultSetMapper<DCAEServiceObjec
public DCAEServiceObject map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
DCAEServiceObject object = new DCAEServiceObject();
object.setServiceId(resultSet.getString("service_id"));
- object.setTypeName(resultSet.getString("type_name"));
+ object.setTypeId(resultSet.getString("type_id"));
object.setVnfId(resultSet.getString("vnf_id"));
object.setVnfType(resultSet.getString("vnf_type"));
object.setVnfLocation(resultSet.getString("vnf_location"));
diff --git a/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java b/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java
index bbd9903..dc64423 100644
--- a/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java
+++ b/src/main/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapper.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.dbthings.mappers;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.dbthings.mappers;
+
import org.openecomp.dcae.inventory.dbthings.models.DCAEServiceTypeObject;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.StatementContext;
@@ -31,6 +28,7 @@ import org.skife.jdbi.v2.tweak.ResultSetMapper;
import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Timestamp;
import java.util.Arrays;
/**
@@ -41,7 +39,9 @@ public class DCAEServiceTypeObjectMapper implements ResultSetMapper<DCAEServiceT
@Override
public DCAEServiceTypeObject map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
DCAEServiceTypeObject object = new DCAEServiceTypeObject();
+ object.setTypeId(resultSet.getString("type_id"));
object.setTypeName(resultSet.getString("type_name"));
+ object.setTypeVersion(resultSet.getInt("type_version"));
object.setOwner(resultSet.getString("owner"));
String[] vnfTypes = (String[]) resultSet.getArray("vnf_types").getArray();
object.setVnfTypes(Arrays.asList(vnfTypes));
@@ -61,7 +61,12 @@ public class DCAEServiceTypeObjectMapper implements ResultSetMapper<DCAEServiceT
}
object.setBlueprintTemplate(resultSet.getString("blueprint_template"));
+ object.setAsdcServiceId(resultSet.getString("asdc_service_id"));
+ object.setAsdcResourceId(resultSet.getString("asdc_resource_id"));
object.setCreated(new DateTime(resultSet.getTimestamp("created")));
+
+ Timestamp deactivated = resultSet.getTimestamp("deactivated");
+ object.setDeactivated(deactivated == null ? null : new DateTime(deactivated));
return object;
}
diff --git a/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceComponentObject.java b/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceComponentObject.java
index f7b783e..0ec9c19 100644
--- a/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceComponentObject.java
+++ b/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceComponentObject.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.dbthings.models;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.dbthings.models;
+
import io.swagger.model.DCAEServiceComponentRequest;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
diff --git a/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceObject.java b/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceObject.java
index 5defd46..4374acd 100644
--- a/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceObject.java
+++ b/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceObject.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.dbthings.models;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.dbthings.models;
+
import io.swagger.model.DCAEServiceRequest;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -38,7 +35,7 @@ public class DCAEServiceObject {
}
private String serviceId = null;
- private String typeName = null;
+ private String typeId = null;
private DateTime created = null;
private DateTime modified = null;
private String vnfId = null;
@@ -57,12 +54,12 @@ public class DCAEServiceObject {
this.serviceId = serviceId;
}
- public String getTypeName() {
- return typeName;
+ public String getTypeId() {
+ return typeId;
}
- public void setTypeName(String typeName) {
- this.typeName = typeName;
+ public void setTypeId(String typeId) {
+ this.typeId = typeId;
}
public DateTime getCreated() {
@@ -135,7 +132,7 @@ public class DCAEServiceObject {
public DCAEServiceObject(String serviceId, DCAEServiceRequest request) {
DateTime now = DateTime.now(DateTimeZone.UTC);
this.setServiceId(serviceId);
- this.setTypeName(request.getTypeName());
+ this.setTypeId(request.getTypeId());
this.setVnfId(request.getVnfId());
this.setVnfType(request.getVnfType());
this.setVnfLocation(request.getVnfLocation());
@@ -158,7 +155,7 @@ public class DCAEServiceObject {
this.setCreated(source.getCreated());
// Mutable fields
- this.setTypeName(updateRequest.getTypeName());
+ this.setTypeId(updateRequest.getTypeId());
this.setVnfId(updateRequest.getVnfId());
this.setVnfType(updateRequest.getVnfType());
this.setVnfLocation(updateRequest.getVnfLocation());
diff --git a/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java b/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java
index 1213207..b57a28f 100644
--- a/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java
+++ b/src/main/java/org/openecomp/dcae/inventory/dbthings/models/DCAEServiceTypeObject.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.dbthings.models;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.dbthings.models;
+
import org.joda.time.DateTime;
import java.util.List;
@@ -34,13 +31,26 @@ import java.util.List;
*/
public class DCAEServiceTypeObject {
+ private String typeId = null;
private String typeName = null;
+ private Integer typeVersion = null;
+ private String blueprintTemplate = null;
private String owner = null;
private List<String> vnfTypes = null;
private List<String> serviceIds = null;
private List<String> serviceLocations = null;
- private String blueprintTemplate = null;
+ private String asdcServiceId = null;
+ private String asdcResourceId = null;
private DateTime created = null;
+ private DateTime deactivated = null;
+
+ public String getTypeId() {
+ return typeId;
+ }
+
+ public void setTypeId(String typeId) {
+ this.typeId = typeId;
+ }
public String getTypeName() {
return typeName;
@@ -50,6 +60,22 @@ public class DCAEServiceTypeObject {
this.typeName = typeName;
}
+ public Integer getTypeVersion() {
+ return typeVersion;
+ }
+
+ public void setTypeVersion(Integer typeVersion) {
+ this.typeVersion = typeVersion;
+ }
+
+ public String getBlueprintTemplate() {
+ return blueprintTemplate;
+ }
+
+ public void setBlueprintTemplate(String blueprintTemplate) {
+ this.blueprintTemplate = blueprintTemplate;
+ }
+
public String getOwner() {
return owner;
}
@@ -82,12 +108,20 @@ public class DCAEServiceTypeObject {
this.serviceLocations = serviceLocations;
}
- public String getBlueprintTemplate() {
- return blueprintTemplate;
+ public String getAsdcServiceId() {
+ return asdcServiceId;
}
- public void setBlueprintTemplate(String blueprintTemplate) {
- this.blueprintTemplate = blueprintTemplate;
+ public void setAsdcServiceId(String asdcServiceId) {
+ this.asdcServiceId = asdcServiceId;
+ }
+
+ public String getAsdcResourceId() {
+ return asdcResourceId;
+ }
+
+ public void setAsdcResourceId(String asdcResourceId) {
+ this.asdcResourceId = asdcResourceId;
}
public DateTime getCreated() {
@@ -98,4 +132,11 @@ public class DCAEServiceTypeObject {
this.created = created;
}
+ public DateTime getDeactivated() {
+ return deactivated;
+ }
+
+ public void setDeactivated(DateTime deactivated) {
+ this.deactivated = deactivated;
+ }
}
diff --git a/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerClientException.java b/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerClientException.java
index 5fde36b..eb30ae7 100644
--- a/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerClientException.java
+++ b/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerClientException.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.exceptions;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.exceptions;
+
/**
* Created by mhwang on 5/13/16.
*/
diff --git a/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerConnectionException.java b/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerConnectionException.java
index b901915..2b9e6e7 100644
--- a/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerConnectionException.java
+++ b/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerConnectionException.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.exceptions;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.exceptions;
+
/**
* Created by mhwang on 8/23/16.
*/
diff --git a/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerTimeoutException.java b/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerTimeoutException.java
index 5d76de6..8aa9255 100644
--- a/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerTimeoutException.java
+++ b/src/main/java/org/openecomp/dcae/inventory/exceptions/DCAEControllerTimeoutException.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.exceptions;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.exceptions;
+
/**
* Created by mhwang on 8/23/16.
*/
diff --git a/src/main/java/org/openecomp/dcae/inventory/exceptions/DatabusControllerClientException.java b/src/main/java/org/openecomp/dcae/inventory/exceptions/DatabusControllerClientException.java
index dbc3e3b..6209521 100644
--- a/src/main/java/org/openecomp/dcae/inventory/exceptions/DatabusControllerClientException.java
+++ b/src/main/java/org/openecomp/dcae/inventory/exceptions/DatabusControllerClientException.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.exceptions;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.exceptions;
+
/**
* Created by mhwang on 5/25/16.
*/
diff --git a/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DBIExceptionMapper.java b/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DBIExceptionMapper.java
new file mode 100644
index 0000000..5dce2dd
--- /dev/null
+++ b/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DBIExceptionMapper.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.dcae.inventory.exceptions.mappers;
+
+import org.openecomp.dcae.inventory.daos.InventoryDAOManager;
+import io.swagger.api.ApiResponseMessage;
+import org.skife.jdbi.v2.exceptions.DBIException;
+import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException;
+import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException;
+import org.skife.jdbi.v2.exceptions.UnableToObtainConnectionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+/**
+ * Created by mhwang on 3/6/17.
+ *
+ * Responsible for handling DBIExceptions for Inventory which are raised by database client calls
+ * http://jdbi.org/apidocs/org/skife/jdbi/v2/exceptions/DBIException.html
+ *
+ * This class is intended to be extended to match on specific exceptions that are derived from DBIException
+ */
+public class DBIExceptionMapper<T extends DBIException> implements ExceptionMapper<T> {
+
+ private final static Logger LOG = LoggerFactory.getLogger(DBIExceptionMapper.class);
+
+ /**
+ * Upon a DBIException, this handler will attempt to re-initialize the Inventory's database connection
+ * and craft a specific message telling the client what to do.
+ *
+ * @param exception Derived class of DBIException
+ * @return Returns a Response with a status code of 502 with an ApiResponseMessage object
+ */
+ @Override
+ public Response toResponse(T exception) {
+ LOG.error("", exception);
+ StringBuilder clientMessage = new StringBuilder("There is a database issue.");
+
+ try {
+ InventoryDAOManager.getInstance().initialize();
+ clientMessage.append(" Connection has been successfully reset. Please try again.");
+ } catch(Exception e) {
+ LOG.error(String.format("Failed to re-initialize database connection: %s", e.getMessage()));
+ clientMessage.append(" Connection reset attempt has failed. Please try again soon.");
+ }
+
+ ApiResponseMessage response = new ApiResponseMessage(ApiResponseMessage.ERROR, clientMessage.toString());
+ return Response.status(Response.Status.BAD_GATEWAY).entity(response).build();
+ }
+
+ // Here are the handlers for specific derived DBIException
+
+ public final static class UnableToObtainConnectionExceptionMapper extends DBIExceptionMapper<UnableToObtainConnectionException> {
+ }
+
+ public final static class UnableToCreateStatementExceptionMapper extends DBIExceptionMapper<UnableToCreateStatementException> {
+ }
+
+ public final static class UnableToExecuteStatementExceptionMapper extends DBIExceptionMapper<UnableToExecuteStatementException> {
+ }
+
+}
diff --git a/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerConnectionExceptionMapper.java b/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerConnectionExceptionMapper.java
index f5efd77..76936e0 100644
--- a/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerConnectionExceptionMapper.java
+++ b/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerConnectionExceptionMapper.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.exceptions.mappers;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.exceptions.mappers;
+
import org.openecomp.dcae.inventory.exceptions.DCAEControllerConnectionException;
import javax.ws.rs.core.Response;
diff --git a/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerExceptionMapper.java b/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerExceptionMapper.java
index 5647b75..b9ffda0 100644
--- a/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerExceptionMapper.java
+++ b/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerExceptionMapper.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.exceptions.mappers;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.exceptions.mappers;
+
import io.swagger.api.ApiResponseMessage;
import javax.ws.rs.core.Response;
diff --git a/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerTimeoutExceptionMapper.java b/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerTimeoutExceptionMapper.java
index 2b850ff..9939aee 100644
--- a/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerTimeoutExceptionMapper.java
+++ b/src/main/java/org/openecomp/dcae/inventory/exceptions/mappers/DCAEControllerTimeoutExceptionMapper.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.exceptions.mappers;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.exceptions.mappers;
+
import org.openecomp.dcae.inventory.exceptions.DCAEControllerTimeoutException;
import javax.ws.rs.core.Response;
diff --git a/src/main/java/org/openecomp/dcae/inventory/providers/NotFoundExceptionMapper.java b/src/main/java/org/openecomp/dcae/inventory/providers/NotFoundExceptionMapper.java
index ce5a55a..0f54b46 100644
--- a/src/main/java/org/openecomp/dcae/inventory/providers/NotFoundExceptionMapper.java
+++ b/src/main/java/org/openecomp/dcae/inventory/providers/NotFoundExceptionMapper.java
@@ -1,28 +1,25 @@
-package org.openecomp.dcae.inventory.providers;
-
-/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 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
- *
+ *
+ * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
+ * ============LICENSE_END=========================================================
*/
+package org.openecomp.dcae.inventory.providers;
+
import io.swagger.api.ApiResponseMessage;
import io.swagger.api.NotFoundException;