2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.synchronizer;
28 import org.openecomp.cl.api.Logger;
29 import org.openecomp.cl.eelf.LoggerFactory;
30 import org.openecomp.sparky.dal.rest.OperationResult;
31 import org.openecomp.sparky.dal.rest.RestDataProvider;
32 import org.openecomp.sparky.logging.AaiUiMsgs;
35 * The Class IndexIntegrityValidator.
39 public class IndexIntegrityValidator implements IndexValidator {
41 private static final Logger LOG =
42 LoggerFactory.getInstance().getLogger(IndexIntegrityValidator.class);
46 private String indexName;
47 private String indexType;
48 private String tableConfigJson;
50 private final RestDataProvider restDataProvider;
53 * Instantiates a new index integrity validator.
55 * @param restDataProvider the rest data provider
56 * @param indexName the index name
57 * @param indexType the index type
58 * @param host the host
59 * @param port the port
60 * @param tableConfigJson the table config json
62 public IndexIntegrityValidator(RestDataProvider restDataProvider, String indexName,
63 String indexType, String host, String port, String tableConfigJson) {
64 this.restDataProvider = restDataProvider;
67 this.indexName = indexName;
68 this.indexType = indexType;
69 this.tableConfigJson = tableConfigJson;
73 public String getIndexName() {
77 public void setIndexName(String indexName) {
78 this.indexName = indexName;
81 public String getIndexType() {
85 public void setIndexType(String indexType) {
86 this.indexType = indexType;
90 * @see org.openecomp.sparky.synchronizer.IndexValidator#exists()
93 public boolean exists() {
94 final String fullUrlStr = getFullUrl("/" + indexName + "/");
95 OperationResult existsResult = restDataProvider.doHead(fullUrlStr, "application/json");
97 int rc = existsResult.getResultCode();
99 if (rc >= 200 && rc < 300) {
100 LOG.info(AaiUiMsgs.INDEX_EXISTS, indexName);
103 LOG.info(AaiUiMsgs.INDEX_NOT_EXIST, indexName);
109 * @see org.openecomp.sparky.synchronizer.IndexValidator#integrityValid()
112 public boolean integrityValid() {
113 // TODO Auto-generated method stub
115 // System.out.println("IndexIntegrityValidator.integrityValid() for
116 // indexName = " + indexName);
121 * @see org.openecomp.sparky.synchronizer.IndexValidator#createOrRepair()
124 public void createOrRepair() {
125 // TODO Auto-generated method stub
126 String message = "IndexIntegrityValidator.createOrRepair() for indexName = " + indexName;
127 LOG.info(AaiUiMsgs.INFO_GENERIC, message);
129 final String fullUrlStr = getFullUrl("/" + indexName + "/");
130 OperationResult createResult =
131 restDataProvider.doPut(fullUrlStr, tableConfigJson, "application/json");
133 int rc = createResult.getResultCode();
135 if (rc >= 200 && rc < 300) {
136 LOG.info(AaiUiMsgs.INDEX_RECREATED, indexName);
137 } else if (rc == 400) {
138 LOG.info(AaiUiMsgs.INDEX_ALREADY_EXISTS, indexName);
140 LOG.warn(AaiUiMsgs.INDEX_INTEGRITY_CHECK_FAILED, indexName, createResult.getResult());
146 * @see org.openecomp.sparky.synchronizer.IndexValidator#destroyIndex()
149 public void destroyIndex() {
150 // TODO Auto-generated method stub
151 // we don't do this for now
158 * @param resourceUrl the resource url
159 * @return the full url
161 private String getFullUrl(String resourceUrl) {
162 return String.format("http://%s:%s%s", host, port, resourceUrl);