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);
46 public String getHost() {
51 * @param host the host to set
53 public void setHost(String host) {
60 public String getPort() {
65 * @param port the port to set
67 public void setPort(String port) {
72 * @return the tableConfigJson
74 public String getTableConfigJson() {
75 return tableConfigJson;
79 * @param tableConfigJson the tableConfigJson to set
81 public void setTableConfigJson(String tableConfigJson) {
82 this.tableConfigJson = tableConfigJson;
88 public static Logger getLog() {
93 * @return the restDataProvider
95 public RestDataProvider getRestDataProvider() {
96 return restDataProvider;
100 private String indexName;
101 private String indexType;
102 private String tableConfigJson;
104 private final RestDataProvider restDataProvider;
107 * Instantiates a new index integrity validator.
109 * @param restDataProvider the rest data provider
110 * @param indexName the index name
111 * @param indexType the index type
112 * @param host the host
113 * @param port the port
114 * @param tableConfigJson the table config json
116 public IndexIntegrityValidator(RestDataProvider restDataProvider, String indexName,
117 String indexType, String host, String port, String tableConfigJson) {
118 this.restDataProvider = restDataProvider;
121 this.indexName = indexName;
122 this.indexType = indexType;
123 this.tableConfigJson = tableConfigJson;
127 public String getIndexName() {
131 public void setIndexName(String indexName) {
132 this.indexName = indexName;
135 public String getIndexType() {
139 public void setIndexType(String indexType) {
140 this.indexType = indexType;
146 * @see org.onap.aai.sparky.synchronizer.IndexValidator#exists()
149 public boolean exists() {
150 final String fullUrlStr = getFullUrl("/" + indexName + "/");
151 OperationResult existsResult = restDataProvider.doHead(fullUrlStr, "application/json");
153 int rc = existsResult.getResultCode();
155 if (rc >= 200 && rc < 300) {
156 LOG.info(AaiUiMsgs.INDEX_EXISTS, indexName);
159 LOG.info(AaiUiMsgs.INDEX_NOT_EXIST, indexName);
167 * @see org.onap.aai.sparky.synchronizer.IndexValidator#integrityValid()
170 public boolean integrityValid() {
171 // TODO Auto-generated method stub
173 // System.out.println("IndexIntegrityValidator.integrityValid() for
174 // indexName = " + indexName);
181 * @see org.onap.aai.sparky.synchronizer.IndexValidator#createOrRepair()
184 public void createOrRepair() {
185 // TODO Auto-generated method stub
186 String message = "IndexIntegrityValidator.createOrRepair() for indexName = " + indexName;
187 LOG.info(AaiUiMsgs.INFO_GENERIC, message);
189 final String fullUrlStr = getFullUrl("/" + indexName + "/");
190 OperationResult createResult =
191 restDataProvider.doPut(fullUrlStr, tableConfigJson, "application/json");
193 int rc = createResult.getResultCode();
195 if (rc >= 200 && rc < 300) {
196 LOG.info(AaiUiMsgs.INDEX_RECREATED, indexName);
197 } else if (rc == 400) {
198 LOG.info(AaiUiMsgs.INDEX_ALREADY_EXISTS, indexName);
200 LOG.warn(AaiUiMsgs.INDEX_INTEGRITY_CHECK_FAILED, indexName, createResult.getResult());
208 * @see org.onap.aai.sparky.synchronizer.IndexValidator#destroyIndex()
211 public void destroyIndex() {
212 // TODO Auto-generated method stub
213 // we don't do this for now
220 * @param resourceUrl the resource url
221 * @return the full url
223 private String getFullUrl(String resourceUrl) {
224 return String.format("http://%s:%s%s", host, port, resourceUrl);