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);
43 private String indexName;
44 private String indexType;
45 private String tableConfigJson;
47 private final RestDataProvider restDataProvider;
50 * Instantiates a new index integrity validator.
52 * @param restDataProvider the rest data provider
53 * @param indexName the index name
54 * @param indexType the index type
55 * @param host the host
56 * @param port the port
57 * @param tableConfigJson the table config json
59 public IndexIntegrityValidator(RestDataProvider restDataProvider, String indexName,
60 String indexType, String host, String port, String tableConfigJson) {
61 this.restDataProvider = restDataProvider;
64 this.indexName = indexName;
65 this.indexType = indexType;
66 this.tableConfigJson = tableConfigJson;
70 public String getIndexName() {
74 public void setIndexName(String indexName) {
75 this.indexName = indexName;
78 public String getIndexType() {
82 public void setIndexType(String indexType) {
83 this.indexType = indexType;
87 * @see org.onap.aai.sparky.synchronizer.IndexValidator#exists()
90 public boolean exists() {
91 final String fullUrlStr = getFullUrl("/" + indexName + "/");
92 OperationResult existsResult = restDataProvider.doHead(fullUrlStr, "application/json");
94 int rc = existsResult.getResultCode();
96 if (rc >= 200 && rc < 300) {
97 LOG.info(AaiUiMsgs.INDEX_EXISTS, indexName);
100 LOG.info(AaiUiMsgs.INDEX_NOT_EXIST, indexName);
106 * @see org.onap.aai.sparky.synchronizer.IndexValidator#integrityValid()
109 public boolean integrityValid() {
110 // TODO Auto-generated method stub
112 // System.out.println("IndexIntegrityValidator.integrityValid() for
113 // indexName = " + indexName);
118 * @see org.onap.aai.sparky.synchronizer.IndexValidator#createOrRepair()
121 public void createOrRepair() {
122 // TODO Auto-generated method stub
123 String message = "IndexIntegrityValidator.createOrRepair() for indexName = " + indexName;
124 LOG.info(AaiUiMsgs.INFO_GENERIC, message);
126 final String fullUrlStr = getFullUrl("/" + indexName + "/");
127 OperationResult createResult =
128 restDataProvider.doPut(fullUrlStr, tableConfigJson, "application/json");
130 int rc = createResult.getResultCode();
132 if (rc >= 200 && rc < 300) {
133 LOG.info(AaiUiMsgs.INDEX_RECREATED, indexName);
134 } else if (rc == 400) {
135 LOG.info(AaiUiMsgs.INDEX_ALREADY_EXISTS, indexName);
137 LOG.warn(AaiUiMsgs.INDEX_INTEGRITY_CHECK_FAILED, indexName, createResult.getResult());
143 * @see org.onap.aai.sparky.synchronizer.IndexValidator#destroyIndex()
146 public void destroyIndex() {
147 // TODO Auto-generated method stub
148 // we don't do this for now
155 * @param resourceUrl the resource url
156 * @return the full url
158 private String getFullUrl(String resourceUrl) {
159 return String.format("http://%s:%s%s", host, port, resourceUrl);