From f0c40a75305068738f0bedfc282f71f826b408ce Mon Sep 17 00:00:00 2001 From: Arthur Martella Date: Fri, 15 Mar 2019 12:31:06 -0400 Subject: Initial upload of F-GPS seed code 14/21 Includes: API annotations API beans API config code API DAO code Change-Id: I2a557bdd814be82c4f00f4fc3965033208b80c5e Issue-ID: OPTFRA-440 Signed-off-by: arthur.martella.1@att.com --- .../onap/fgps/api/annotation/AafRoleRequired.java | 74 ++++++ .../fgps/api/annotation/BasicAuthRequired.java | 59 +++++ .../api/annotation/PropertyBasedAuthorization.java | 64 +++++ .../org/onap/fgps/api/beans/KeySpaceRequest.java | 44 ++++ .../main/java/org/onap/fgps/api/beans/Status.java | 65 +++++ .../org/onap/fgps/api/beans/schema/Schema.java | 262 +++++++++++++++++++++ .../java/org/onap/fgps/api/config/HttpConfig.java | 82 +++++++ .../onap/fgps/api/config/SpringServletConfig.java | 71 ++++++ .../main/java/org/onap/fgps/api/dao/SchemaDAO.java | 177 ++++++++++++++ .../fgps/api/dao/ValetServicePlacementDAO.java | 155 ++++++++++++ 10 files changed, 1053 insertions(+) create mode 100644 valetapi/src/main/java/org/onap/fgps/api/annotation/AafRoleRequired.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/annotation/BasicAuthRequired.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/annotation/PropertyBasedAuthorization.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/beans/KeySpaceRequest.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/beans/Status.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/beans/schema/Schema.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/config/HttpConfig.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/config/SpringServletConfig.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/dao/SchemaDAO.java create mode 100644 valetapi/src/main/java/org/onap/fgps/api/dao/ValetServicePlacementDAO.java diff --git a/valetapi/src/main/java/org/onap/fgps/api/annotation/AafRoleRequired.java b/valetapi/src/main/java/org/onap/fgps/api/annotation/AafRoleRequired.java new file mode 100644 index 0000000..49398c3 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/annotation/AafRoleRequired.java @@ -0,0 +1,74 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface AafRoleRequired { + /** + * Annotates a method to indicate that AAF authorization is required to execute. + * + * If AAF authentication is used, auth.properties must contain valet.aaf.name and valet.aaf.pass, which contains this application's + * AAF credentials. + * + * See also @PropertyBasedAuthorization. + */ + + /** + * Marks the role required in AAF. + * For example, @AafRoleRequired(roleRequired="portal.admin") will check AAF for the "portal.admin" role. + */ + String roleRequired() default ""; + + /** + * If roleRequired is null or blank, marks the property in auth.properties which contains the role required by AAF. + * The property in auth.properties must end with ".role". The property specified in the annotation may omit that suffix. + * + * For example, if auth.properties contains "portal.admin.role=portal.admin", then either @AafRoleRequired(roleProperty="portal.admin.role") + * or @AafRoleRequired(roleProperty="portal.admin") will check AAF for the "portal.admin" role. + * + * If a roleProperty is specified in an AafRoleRequired annotation and the corresponding role (with or without ".role") is not + * present in auth.properties, a MissingRoleException will be thrown. + */ + String roleProperty() default ""; +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/annotation/BasicAuthRequired.java b/valetapi/src/main/java/org/onap/fgps/api/annotation/BasicAuthRequired.java new file mode 100644 index 0000000..a10fd61 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/annotation/BasicAuthRequired.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface BasicAuthRequired { + /** + * Annotates a method that BasicAuth is required to execute. + * + * If a method is annotated with @BasicAuth(authRequired="appname"), then auth.properties must include properties named + * appname.name and appname.pass . If appname.name is x and appname.pass is the encrypted value of y, then the headers + * for calls to this method must contain header "Authentication: Basic [base64 encoded x:y]". + * + * See also @PropertyBasedAuthorization. + */ + + String authRequired() default ""; +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/annotation/PropertyBasedAuthorization.java b/valetapi/src/main/java/org/onap/fgps/api/annotation/PropertyBasedAuthorization.java new file mode 100644 index 0000000..9b77c0d --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/annotation/PropertyBasedAuthorization.java @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.annotation; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(RUNTIME) +@Target(METHOD) +public @interface PropertyBasedAuthorization { + /** + * Annotates a method whose authorization requirements are defined in a property file. + * + * The auth.properties file should contain one or more lines for each method annotated with this annotation. + * If the annotation value is "x", auth.properties should contain either "x.aaf" or "x.basic". + * If "x.aaf" is present, the user will be authenticated using AAF and authorized if they have the role which is value of x.aaf. + * (See also @AafRoleRequired .) + * If "x.basic" is present, with a value of "y", the user will be authorized using Basicauth with username of "y.name" and (encrypted) password of "y.pass". + * (See also @BasicAuthRequired .) + * + * If AAF authentication is used, auth.properties must contain valet.aaf.name and valet.aaf.pass, which contains this application's + * AAF credentials. + * + */ + String value(); +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/beans/KeySpaceRequest.java b/valetapi/src/main/java/org/onap/fgps/api/beans/KeySpaceRequest.java new file mode 100644 index 0000000..7fc0bc6 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/beans/KeySpaceRequest.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright-2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.beans; + +public class KeySpaceRequest { + private String durabilityOfWrites; +} + + diff --git a/valetapi/src/main/java/org/onap/fgps/api/beans/Status.java b/valetapi/src/main/java/org/onap/fgps/api/beans/Status.java new file mode 100644 index 0000000..50a1484 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/beans/Status.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.beans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +@JsonRootName(value="status") +public class Status { + @JsonProperty(value="status_code") + private String statusCode; + + @JsonProperty(value="status_message") + private String statusMessage; + + public Status(String statusCode, String statusMessage) { + super(); + this.statusCode = statusCode; + this.statusMessage = statusMessage; + } + + public String getStatusCode() { + return statusCode; + } + + public String getStatusMessage() { + return statusMessage; + } + +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/beans/schema/Schema.java b/valetapi/src/main/java/org/onap/fgps/api/beans/schema/Schema.java new file mode 100644 index 0000000..a9f1fbb --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/beans/schema/Schema.java @@ -0,0 +1,262 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.beans.schema; + +import org.json.simple.JSONObject; +import org.onap.fgps.api.utils.Constants; +import org.springframework.stereotype.Component; + +import com.fasterxml.uuid.Generators; + +@Component +public class Schema { + @SuppressWarnings("unchecked") + public static JSONObject getCommonTableSchema() { + JSONObject jsonRequest = new JSONObject(); + JSONObject properties = new JSONObject(); + JSONObject compression = new JSONObject(); + JSONObject compaction = new JSONObject(); + JSONObject consistencyInfo = new JSONObject(); + + compression.put("sstable_compression", "DeflateCompressor"); + compression.put("chunk_length_kb", 64); + + compaction.put("class", "SizeTieredCompactionStrategy"); + compaction.put("min_threshold", 6); + + properties.put("compression", compression); + properties.put("compaction", compaction); + + consistencyInfo.put("type", "eventual"); + + jsonRequest.put("properties", properties); + jsonRequest.put("consistencyInfo", consistencyInfo); + return jsonRequest; + } + + @SuppressWarnings("unchecked") + public static String getRequestTableSchema() { + JSONObject fields = new JSONObject(); + + fields.put("request_id", "varchar"); + fields.put("timestamp", "varchar"); + fields.put("request", "varchar"); + fields.put("PRIMARY KEY", "(request_id)"); + + JSONObject jsonRequest = getCommonTableSchema(); + jsonRequest.put("fields", fields); + return jsonRequest.toJSONString(); + } + + @SuppressWarnings("unchecked") + public static String getResultsTableSchema() { + JSONObject fields = new JSONObject(); + + fields.put("request_id", "varchar"); + fields.put("status", "varchar"); + fields.put("timestamp", "varchar"); + fields.put("result", "varchar"); + fields.put("PRIMARY KEY", "(request_id)"); + + JSONObject jsonRequest = getCommonTableSchema(); + jsonRequest.put("fields", fields); + return jsonRequest.toJSONString(); + } + + @SuppressWarnings("unchecked") + public static String getGroupsRulesTableSchema() { + JSONObject fields = new JSONObject(); + + fields.put("id", "varchar"); + fields.put("app_scope", "varchar"); + fields.put("type", "varchar"); + fields.put("level", "varchar"); + fields.put("members", "varchar"); + fields.put("description", "varchar"); + fields.put("groups", "varchar"); + fields.put("status", "varchar"); + fields.put("timestamp", "varchar"); + fields.put("PRIMARY KEY", "(id)"); + + JSONObject jsonRequest = getCommonTableSchema(); + jsonRequest.put("fields", fields); + return jsonRequest.toJSONString(); + + } + + @SuppressWarnings("unchecked") + public static String getStacksTableSchema() { + JSONObject fields = new JSONObject(); + + fields.put("id", "varchar"); + fields.put("last_status", "varchar"); + fields.put("datacenter", "varchar"); + fields.put("stack_name", "varchar"); + fields.put("uuid", "varchar"); + fields.put("tenant_id", "varchar"); + fields.put("metadata", "varchar"); + fields.put("servers", "varchar"); + fields.put("prior_servers", "varchar"); + fields.put("state", "varchar"); + fields.put("prior_State", "varchar"); + fields.put("timestamp", "varchar"); + fields.put("PRIMARY KEY", "(id)"); + + JSONObject jsonRequest = getCommonTableSchema(); + jsonRequest.put("fields", fields); + return jsonRequest.toJSONString(); + } + + @SuppressWarnings("unchecked") + public static String getStacksIdMapTableSchema() { + JSONObject fields = new JSONObject(); + + fields.put("request_id", "varchar"); + fields.put("stack_id", "varchar"); + fields.put("timestamp", "varchar"); + fields.put("PRIMARY KEY", "(request_id)"); + JSONObject jsonRequest = getCommonTableSchema(); + jsonRequest.put("fields", fields); + return jsonRequest.toJSONString(); + } + + @SuppressWarnings("unchecked") + public static String getResourcesTableSchema() { + JSONObject fields = new JSONObject(); + + fields.put("id", "varchar"); + fields.put("url", "varchar"); + fields.put("resource", "varchar"); + fields.put("timestamp", "varchar"); + fields.put("PRIMARY KEY", "(id)"); + fields.put("requests", "varchar"); + + JSONObject jsonRequest = getCommonTableSchema(); + jsonRequest.put("fields", fields); + return jsonRequest.toJSONString(); + } + @SuppressWarnings("unchecked") + public static String getRegionsTableSchema() { + JSONObject fields = new JSONObject(); + + fields.put("region_id ", "varchar"); + fields.put("PRIMARY KEY", "(region_id)"); + fields.put("timestamp", "varchar"); + fields.put("last_updated ", "varchar"); + fields.put("keystone_url", "varchar"); + fields.put("locked_by", "varchar"); + fields.put("locked_time ", "varchar"); + //fields.put("locked_time ", "varchar"); + fields.put("expire_time", "varchar"); + + JSONObject jsonRequest = getCommonTableSchema(); + jsonRequest.put("fields", fields); + return jsonRequest.toJSONString(); + } + + @SuppressWarnings("unchecked") + public static String getGroupsTableSchema() { + JSONObject fields = new JSONObject(); + + fields.put("id ", "varchar"); + fields.put("PRIMARY KEY", "id"); + fields.put("uuid", "varchar"); + fields.put("type ", "varchar"); + fields.put("level", "varchar"); + fields.put("factory", "varchar"); + fields.put("rule_id ", "varchar"); + fields.put("metadata ", "varchar"); + fields.put("server_list", "varchar"); + fields.put("member_hosts", "varchar"); + fields.put("status", "varchar"); + + + JSONObject jsonRequest = getCommonTableSchema(); + jsonRequest.put("fields", fields); + return jsonRequest.toJSONString(); + } + @SuppressWarnings("unchecked") + public String formMsoInsertUpdateRequest(String requestId, String operation, String request) { + JSONObject jsonRequest = new JSONObject(); + JSONObject values = new JSONObject(); + JSONObject consistencyInfo = new JSONObject(); + String request_id = requestId == null ? Generators.timeBasedGenerator().generate().toString() + : operation + '-' + requestId; + + values.put(Constants.HEAT_REQUEST_REQUEST_ID, request_id); + values.put(Constants.HEAT_REQUEST_TIMESTAMP, System.currentTimeMillis()); + values.put(Constants.HEAT_REQUEST_REQUEST, request); + consistencyInfo.put("type", "eventual"); + + jsonRequest.put("values", values); + jsonRequest.put("consistencyInfo", consistencyInfo); + + return jsonRequest.toJSONString(); + } + @SuppressWarnings("unchecked") + public String formHealthCheckRequest(String requestId, String operation, String request) { + JSONObject jsonRequest = new JSONObject(); + JSONObject values = new JSONObject(); + JSONObject consistencyInfo = new JSONObject(); + String request_id = requestId == null ? Generators.timeBasedGenerator().generate().toString() + : operation + '-' + requestId; + + values.put(Constants.HEAT_REQUEST_REQUEST_ID, request_id); + values.put(Constants.HEAT_REQUEST_TIMESTAMP, -1); + values.put(Constants.HEAT_REQUEST_REQUEST, request); + consistencyInfo.put("type", "eventual"); + + jsonRequest.put("values", values); + jsonRequest.put("consistencyInfo", consistencyInfo); + + return jsonRequest.toJSONString(); + } + + + @SuppressWarnings("unchecked") + public String formMsoDeleteRequest() { + JSONObject jsonRequest = new JSONObject(); + JSONObject consistencyInfo = new JSONObject(); + + consistencyInfo.put("type", "eventual"); + jsonRequest.put("consistencyInfo", consistencyInfo); + + return jsonRequest.toJSONString(); + } +} + diff --git a/valetapi/src/main/java/org/onap/fgps/api/config/HttpConfig.java b/valetapi/src/main/java/org/onap/fgps/api/config/HttpConfig.java new file mode 100644 index 0000000..83fe632 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/config/HttpConfig.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.config; + +import org.apache.catalina.connector.Connector; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class HttpConfig { + @Value("${server.http.port:-1}") + private int httpPort; + + @Bean + public WebServerFactoryCustomizer containerCustomizer() { + System.out.println("In HttpConfig, httpPort = " + httpPort); + + if (httpPort==-1) { + return new WebServerFactoryCustomizer() { + @Override + public void customize(ConfigurableServletWebServerFactory arg0) { + //noop + } + + }; + } + + return new WebServerFactoryCustomizer() { + @Override + public void customize(ConfigurableServletWebServerFactory factory) { + if (factory instanceof TomcatServletWebServerFactory) { + TomcatServletWebServerFactory containerFactory = + (TomcatServletWebServerFactory) factory; + + Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL); + connector.setPort(httpPort); + containerFactory.addAdditionalTomcatConnectors(connector); + } + + } + }; + } +} \ No newline at end of file diff --git a/valetapi/src/main/java/org/onap/fgps/api/config/SpringServletConfig.java b/valetapi/src/main/java/org/onap/fgps/api/config/SpringServletConfig.java new file mode 100644 index 0000000..4fd84df --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/config/SpringServletConfig.java @@ -0,0 +1,71 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.config; + +import org.onap.fgps.api.interceptor.AuthorizationInterceptor; +import org.onap.fgps.api.interceptor.DarknessInterceptor; +import org.onap.fgps.api.interceptor.VersioningInterceptor; +import org.onap.fgps.api.proxy.AAFProxy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +public class SpringServletConfig extends WebMvcConfigurerAdapter { + private final boolean valetDark; + private final String aafUrl; + private final boolean aafAuthFlag; + private final boolean basicAuthFlag; + + @Autowired + public SpringServletConfig(@Value("${valet.dark:false}") boolean valetDark, @Value("${aaf.url.base:}") String aafUrl, @Value("${authentication.aaf:true}") boolean aafAuthFlag, @Value("${authentication.basic:true}") boolean basicAuthFlag) { + this.valetDark = valetDark; + this.aafUrl = aafUrl; + this.aafAuthFlag = aafAuthFlag; + this.basicAuthFlag = basicAuthFlag; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + if (valetDark) registry.addInterceptor(new DarknessInterceptor()); + if (aafUrl!=null && aafUrl.length()>0) registry.addInterceptor(new AuthorizationInterceptor(new AAFProxy(aafUrl), aafAuthFlag, basicAuthFlag)); + registry.addInterceptor(new VersioningInterceptor()); + } +} \ No newline at end of file diff --git a/valetapi/src/main/java/org/onap/fgps/api/dao/SchemaDAO.java b/valetapi/src/main/java/org/onap/fgps/api/dao/SchemaDAO.java new file mode 100644 index 0000000..23ed463 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/dao/SchemaDAO.java @@ -0,0 +1,177 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.dao; + +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.Properties; + +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.onap.fgps.api.beans.schema.Schema; +import org.onap.fgps.api.logging.EELFLoggerDelegate; +import org.onap.fgps.api.proxy.DBProxy; +import org.onap.fgps.api.utils.Constants; +import org.onap.fgps.api.utils.DBInitializationRequests; +import org.onap.fgps.api.utils.MusicDBConstants; +import org.springframework.stereotype.Component; +import org.onap.fgps.api.utils.UserUtils; + +@Component +public class SchemaDAO { + private static EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(SchemaDAO.class); + InputStream inputStream; + + public String initializeDatabase() { + Properties props = new Properties(); + String propFileName = "resources.properties"; + InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); + try { + if (inputStream != null) { + props.load(inputStream); + } else { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"DBProxy : inputstream is not"); + } + } catch (IOException e) { + e.printStackTrace(); + LOGGER.error(EELFLoggerDelegate.applicationLogger,"initializeDatabase : Error while loading "+propFileName+", Error details : "+ e.getMessage()); + LOGGER.error(EELFLoggerDelegate.errorLogger,"initializeDatabase : Error while loading "+propFileName+", Error details : "+ e.getMessage()); + } + LOGGER.info(EELFLoggerDelegate.applicationLogger,"SchemaDAO : initializeDatabase called"); + + String keyspace = UserUtils.htmlEscape(props.getProperty("music.Keyspace")); + LOGGER.info(EELFLoggerDelegate.applicationLogger, "keyspace: " + keyspace); + if (keyspace!=null && keyspace.length()>0 && !keyspace.equalsIgnoreCase("false")) { + String dataCenterList = UserUtils.htmlEscape(props.getProperty("music.keyspace.data.centers")); + if (dataCenterList==null || dataCenterList.length()==0) { + // If music.keyspace.data.centers is not specified, use old behavior: data.center.one, .two, and .three get initialized with replication factor 3 + createKeySpace(keyspace, UserUtils.htmlEscape(props.getProperty("data.center.one")), UserUtils.htmlEscape(props.getProperty("data.center.two")), UserUtils.htmlEscape(props.getProperty("data.center.three")) ); + } else { + // If music.keyspace.data.centers is specified, it must be a pipe separated list, and music.keyspace.replication.factor must be an integer which is the replication factor + int replicationFactor = Integer.parseInt(props.getProperty("music.keyspace.replication.factor")); + createKeyspaceWithReplicationFactor(keyspace, dataCenterList, replicationFactor); + } + } + + createTable(keyspace, Constants.SERVICE_PLACEMENTS_REQUEST_TABLE, Schema.getRequestTableSchema()); + createTable(keyspace, Constants.TABLE_RESULT, Schema.getResultsTableSchema()); + createTable(keyspace, Constants.TABLE_GROUP_RULES, Schema.getGroupsRulesTableSchema()); + createTable(keyspace, Constants.TABLE_STACKS, Schema.getStacksTableSchema()); + createTable(keyspace, Constants.TABLE_STACKS_ID_MAP, Schema.getStacksIdMapTableSchema()); + createTable(keyspace, Constants.TABLE_RESOURCES, Schema.getResourcesTableSchema()); + createTable(keyspace, Constants.TABLE_REGIONS, Schema.getRegionsTableSchema()); + createTable(keyspace, Constants.TABLE_Groups, Schema.getGroupsTableSchema()); + + + System.out.println("Tables created"); + return ""; + } + + /** + * + * @param keyspace - music.Keyspace - name of the music keyspace + * @param dataCenterList - music.keyspace.data.centers - pipe separated list of data center names, e.g., "DC1|DC2|DC3|DC4" + * @param replicationFactor - music.keyspace.replication.factor - replication factor for each keyspace + * @return a String representing the response from Music, or an error string if it fails + */ + private String createKeyspaceWithReplicationFactor(String keyspace, String dataCenterList, int replicationFactor) { + LOGGER.info(EELFLoggerDelegate.applicationLogger, "SchemaDAO.createKeyspaceWithReplicationFactor"); + MessageFormat uri = new MessageFormat(MusicDBConstants.CREATE_KEYSPACE); + + Object data[] = { keyspace }; + String keyUrl = uri.format(data); + DBProxy dbProxy = new DBProxy(); + + String targetString = DBInitializationRequests.KEYSPACE_WITH_RF; + StringBuffer sb = new StringBuffer(); + String sep = ""; + java.util.StringTokenizer st = new java.util.StringTokenizer(dataCenterList, "|"); + while (st.hasMoreTokens()) { + String token = st.nextToken(); + sb.append(sep + "\"" + token + "\":" + replicationFactor); + sep = ","; + } + targetString = targetString.replaceAll("DATA_CENTER_INFO", sb.toString()); + + LOGGER.info(EELFLoggerDelegate.applicationLogger, "keyspace string = " + targetString); + return dbProxy.post(keyUrl, targetString); + } + + /** + * + * @param keySpaceName + * @param DC1 Data Center Name + * @param DC2 Data Center Name + * @param DC3 Data Center Name + * @return + */ + public String createKeySpace(String keySpaceName,String DC1,String DC2,String DC3) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"SchemaDAO : createKeySpace called"); + MessageFormat uri = new MessageFormat(MusicDBConstants.CREATE_KEYSPACE); + JSONParser parser = new JSONParser(); + JSONObject jsonRequest = null; + try { + jsonRequest = (JSONObject) parser.parse(DBInitializationRequests.KEYSPACE_REQUEST); + Object data[] = { keySpaceName }; + String keyUrl = uri.format(data); + DBProxy dbProxy = new DBProxy(); + System.out.println(jsonRequest.toJSONString().replace("DC1", DC1).replace("DC2", DC2).replace("DC3", DC3)); + return dbProxy.post(keyUrl, jsonRequest.toJSONString().replace("DC1", DC1).replace("DC2", DC2).replace("DC3", DC3)); + } catch (ParseException e) { + e.printStackTrace(); + LOGGER.error(EELFLoggerDelegate.applicationLogger,"createKeySpace : Error details : "+ e.getMessage()); + LOGGER.error(EELFLoggerDelegate.errorLogger,"createKeySpace : Error details : "+ e.getMessage()); + return "Error parsing the request.Refer logs for more insight"; + } + } + + public String createTable(String keySpaceName, String tableName, String jsonRequest) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"SchemaDAO : createTable called"); + + MessageFormat uri = new MessageFormat(MusicDBConstants.CREATE_TABLE); + Object data[] = { keySpaceName, tableName }; + + DBProxy dbProxy = new DBProxy(); + System.out.println(jsonRequest); + System.out.println(uri.format(data)); + + return dbProxy.post(uri.format(data), jsonRequest); + } +} diff --git a/valetapi/src/main/java/org/onap/fgps/api/dao/ValetServicePlacementDAO.java b/valetapi/src/main/java/org/onap/fgps/api/dao/ValetServicePlacementDAO.java new file mode 100644 index 0000000..5d9d166 --- /dev/null +++ b/valetapi/src/main/java/org/onap/fgps/api/dao/ValetServicePlacementDAO.java @@ -0,0 +1,155 @@ +/* + * ============LICENSE_START========================================== + * ONAP - F-GPS API + * =================================================================== + * Copyright © 2019 ATT Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.fgps.api.dao; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.json.simple.JSONObject; +import org.onap.fgps.api.logging.EELFLoggerDelegate; +import org.onap.fgps.api.proxy.DBProxy; +import org.onap.fgps.api.utils.Constants; +import org.onap.fgps.api.utils.Helper; +import org.onap.fgps.api.utils.MusicDBConstants; +import org.springframework.stereotype.Component; +import org.onap.fgps.api.utils.UserUtils; + +@Component +public class ValetServicePlacementDAO { + //private static final Logger LOGGER = LoggerFactory.getLogger(ValetServiceApplication.class); + private static EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(SchemaDAO.class); + private String keySpace; + private boolean pingLogFlag; + + public ValetServicePlacementDAO(boolean pingFlag) { + this.pingLogFlag = pingFlag; + Properties props = new Properties(); + String propFileName = "resources.properties"; + InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); + try { + if (inputStream != null) { + props.load(inputStream); + } else { + if(pingLogFlag) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"DBProxy : inputstream is not"); + } + } + } catch (IOException e) { + e.printStackTrace(); + LOGGER.error(EELFLoggerDelegate.applicationLogger,"ValetServicePlacementDAO : Error details : "+ e.getMessage()); + LOGGER.error(EELFLoggerDelegate.errorLogger,"ValetServicePlacementDAO : Error details : "+ e.getMessage()); + } + if(pingLogFlag) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"SchemaDAO : initializeDatabase called"); + } + this.keySpace = UserUtils.htmlEscape(props.getProperty("music.Keyspace")); + } + + public ValetServicePlacementDAO() { + this(true); + } + + public String insertRow(String request) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"ValetServicePlacementDAO : insertRow : inserting the row"); + + DBProxy dbProxy = new DBProxy(); + Object[] params = { this.keySpace, Constants.SERVICE_PLACEMENTS_REQUEST_TABLE }; + String url = Helper.getURI(MusicDBConstants.INSERT_ROWS, params); + return dbProxy.post(url, request); + } + + public String deleteRow(String request_id, String json) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"ValetServicePlacementDAO : deleteRow : deleting the row"); + DBProxy dbProxy = new DBProxy(); + Object[] params = { this.keySpace, Constants.SERVICE_PLACEMENTS_REQUEST_TABLE }; + String url = Helper.getURI(MusicDBConstants.INSERT_ROWS, params); + return dbProxy.delete(url + "?request_id=" + request_id, json); + } + + @SuppressWarnings("unchecked") + public String updateRow(JSONObject values) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"ValetServicePlacementDAO : updateRow : update the row"); + + JSONObject request = new JSONObject(); + JSONObject consistencyInfo = new JSONObject(); + consistencyInfo.put("type", "eventual"); + request.put("values", values); + request.put("consistencyInfo", consistencyInfo); + DBProxy dbProxy = new DBProxy(); + Object[] params = { this.keySpace, Constants.SERVICE_PLACEMENTS_REQUEST_TABLE }; + String url = Helper.getURI(MusicDBConstants.INSERT_ROWS, params); + return dbProxy.put(url, request.toJSONString()); + } + + public String getRow(String request_id) { + if(pingLogFlag) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"ValetServicePlacementDAO : getRow : geting the row"); + } + + DBProxy dbProxy = new DBProxy(pingLogFlag); + Object[] params = { this.keySpace, Constants.SERVICE_PLACEMENTS_REQUEST_TABLE }; + String url = Helper.getURI(MusicDBConstants.INSERT_ROWS, params); + return dbProxy.get(url + "?request_id=" + request_id); + } + + public String getRowFromResults(String request_id) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"ValetServicePlacementDAO : getRowFromResults : geting the row"); + + DBProxy dbProxy = new DBProxy(); + Object[] params = { this.keySpace, Constants.SERVICE_PLACEMENTS_RESULTS_TABLE }; + String url = Helper.getURI(MusicDBConstants.INSERT_ROWS, params); + System.out.println(url + "?request_id=" + request_id); + String result = dbProxy.get(url + "?request_id=" + request_id); + System.out.println(result); + return result; + + } + + public String deleteRowFromResults(String request_id, String request) { + LOGGER.info(EELFLoggerDelegate.applicationLogger,"ValetServicePlacementDAO : deleteRowFromResults : deleting the row"); + + DBProxy dbProxy = new DBProxy(); + Object[] params = { this.keySpace, Constants.SERVICE_PLACEMENTS_RESULTS_TABLE }; + String url = Helper.getURI(MusicDBConstants.INSERT_ROWS, params); + System.out.println(url + "?request_id=" + request_id); + String result = dbProxy.delete(url + "?request_id=" + request_id, request); + System.out.println(result); + return result; + } +} -- cgit 1.2.3-korg