2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.synchronizer;
25 import org.onap.aai.sparky.dal.rest.OperationResult;
26 import org.onap.aai.sparky.dal.rest.RestDataProvider;
27 import org.onap.aai.sparky.logging.AaiUiMsgs;
28 import org.onap.aai.cl.api.Logger;
29 import org.onap.aai.cl.eelf.LoggerFactory;
32 * The Class IndexIntegrityValidator.
36 public class IndexIntegrityValidator implements IndexValidator {
38 private static final Logger LOG =
39 LoggerFactory.getInstance().getLogger(IndexIntegrityValidator.class);
45 public String getHost() {
50 * @param host the host to set
52 public void setHost(String host) {
59 public String getPort() {
64 * @param port the port to set
66 public void setPort(String port) {
71 * @return the tableConfigJson
73 public String getTableConfigJson() {
74 return tableConfigJson;
78 * @param tableConfigJson the tableConfigJson to set
80 public void setTableConfigJson(String tableConfigJson) {
81 this.tableConfigJson = tableConfigJson;
87 public static Logger getLog() {
92 * @return the restDataProvider
94 public RestDataProvider getRestDataProvider() {
95 return restDataProvider;
99 private String indexName;
100 private String indexType;
101 private String tableConfigJson;
103 private final RestDataProvider restDataProvider;
106 * Instantiates a new index integrity validator.
108 * @param restDataProvider the rest data provider
109 * @param indexName the index name
110 * @param indexType the index type
111 * @param host the host
112 * @param port the port
113 * @param tableConfigJson the table config json
115 public IndexIntegrityValidator(RestDataProvider restDataProvider, String indexName,
116 String indexType, String host, String port, String tableConfigJson) {
117 this.restDataProvider = restDataProvider;
120 this.indexName = indexName;
121 this.indexType = indexType;
122 this.tableConfigJson = tableConfigJson;
126 public String getIndexName() {
130 public void setIndexName(String indexName) {
131 this.indexName = indexName;
134 public String getIndexType() {
138 public void setIndexType(String indexType) {
139 this.indexType = indexType;
143 * @see org.onap.aai.sparky.synchronizer.IndexValidator#exists()
146 public boolean exists() {
147 final String fullUrlStr = getFullUrl("/" + indexName + "/");
148 OperationResult existsResult = restDataProvider.doHead(fullUrlStr, "application/json");
150 int rc = existsResult.getResultCode();
152 if (rc >= 200 && rc < 300) {
153 LOG.info(AaiUiMsgs.INDEX_EXISTS, indexName);
156 LOG.info(AaiUiMsgs.INDEX_NOT_EXIST, indexName);
162 * @see org.onap.aai.sparky.synchronizer.IndexValidator#integrityValid()
165 public boolean integrityValid() {
166 // TODO Auto-generated method stub
168 // System.out.println("IndexIntegrityValidator.integrityValid() for
169 // indexName = " + indexName);
174 * @see org.onap.aai.sparky.synchronizer.IndexValidator#createOrRepair()
177 public void createOrRepair() {
178 // TODO Auto-generated method stub
179 String message = "IndexIntegrityValidator.createOrRepair() for indexName = " + indexName;
180 LOG.info(AaiUiMsgs.INFO_GENERIC, message);
182 final String fullUrlStr = getFullUrl("/" + indexName + "/");
183 OperationResult createResult =
184 restDataProvider.doPut(fullUrlStr, tableConfigJson, "application/json");
186 int rc = createResult.getResultCode();
188 if (rc >= 200 && rc < 300) {
189 LOG.info(AaiUiMsgs.INDEX_RECREATED, indexName);
190 } else if (rc == 400) {
191 LOG.info(AaiUiMsgs.INDEX_ALREADY_EXISTS, indexName);
193 LOG.warn(AaiUiMsgs.INDEX_INTEGRITY_CHECK_FAILED, indexName, createResult.getResult());
199 * @see org.onap.aai.sparky.synchronizer.IndexValidator#destroyIndex()
202 public void destroyIndex() {
203 // TODO Auto-generated method stub
204 // we don't do this for now
211 * @param resourceUrl the resource url
212 * @return the full url
214 private String getFullUrl(String resourceUrl) {
215 return String.format("http://%s:%s%s", host, port, resourceUrl);