diff options
author | 2017-09-26 14:00:57 -0400 | |
---|---|---|
committer | 2017-09-26 14:01:41 -0400 | |
commit | c593dfe4c59d37d5d4ea14e3ac31da3318029562 (patch) | |
tree | 76cc5a494f02e14b809caad9c050fbfd6cd61a51 /src/main/java/org/openecomp/sparky/synchronizer/task | |
parent | 6777c6092050a0271c5d7de9c239cf1580d41fa8 (diff) |
Renaming openecomp to onap
Issue-ID: AAI-208
Change-Id: I2bd02287bed376111156aca0100e2b7b74e368e3
Signed-off-by: Arul.Nambi <arul.nambi@amdocs.com>
Diffstat (limited to 'src/main/java/org/openecomp/sparky/synchronizer/task')
10 files changed, 0 insertions, 795 deletions
diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/CollectEntitySelfLinkTask.java b/src/main/java/org/openecomp/sparky/synchronizer/task/CollectEntitySelfLinkTask.java deleted file mode 100644 index e2273cc..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/CollectEntitySelfLinkTask.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.util.function.Supplier; - -import org.openecomp.sparky.dal.NetworkTransaction; -import org.openecomp.sparky.dal.aai.ActiveInventoryDataProvider; -import org.openecomp.sparky.dal.rest.OperationResult; - -/** - * The Class CollectEntitySelfLinkTask. - */ -public class CollectEntitySelfLinkTask implements Supplier<NetworkTransaction> { - - private NetworkTransaction txn; - - private ActiveInventoryDataProvider provider; - - /** - * Instantiates a new collect entity self link task. - * - * @param txn the txn - * @param provider the provider - */ - public CollectEntitySelfLinkTask(NetworkTransaction txn, ActiveInventoryDataProvider provider) { - this.txn = txn; - this.provider = provider; - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public NetworkTransaction get() { - - txn.setTaskAgeInMs(); - - long startTimeInMs = System.currentTimeMillis(); - OperationResult result = null; - try { - result = provider.queryActiveInventoryWithRetries(txn.getLink(), "application/json", 5); - } catch (Exception exc) { - result = new OperationResult(500, - "Caught an exception while trying to resolve link = " + exc.getMessage()); - } finally { - result.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs); - txn.setOperationResult(result); - } - - return txn; - } - -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/CollectEntityTypeSelfLinksTask.java b/src/main/java/org/openecomp/sparky/synchronizer/task/CollectEntityTypeSelfLinksTask.java deleted file mode 100644 index 98f4425..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/CollectEntityTypeSelfLinksTask.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.util.function.Supplier; - -import org.openecomp.sparky.dal.NetworkTransaction; -import org.openecomp.sparky.dal.aai.ActiveInventoryDataProvider; -import org.openecomp.sparky.dal.rest.OperationResult; - -/** - * The Class CollectEntityTypeSelfLinksTask. - */ -public class CollectEntityTypeSelfLinksTask implements Supplier<NetworkTransaction> { - - private ActiveInventoryDataProvider aaiProvider; - - private NetworkTransaction txn; - - /** - * Instantiates a new collect entity type self links task. - * - * @param txn the txn - * @param provider the provider - */ - public CollectEntityTypeSelfLinksTask(NetworkTransaction txn, - ActiveInventoryDataProvider provider) { - this.aaiProvider = provider; - this.txn = txn; - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public NetworkTransaction get() { - - txn.setTaskAgeInMs(); - - long startTimeInMs = System.currentTimeMillis(); - OperationResult result = null; - try { - result = aaiProvider.queryActiveInventoryWithRetries(txn.getLink(), "application/json", 5); - } catch (Exception exc) { - result = new OperationResult(500, - "Caught an exception while trying to resolve link = " + exc.getMessage()); - } finally { - result.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs); - txn.setOperationResult(result); - } - - return txn; - } - -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/GetCrossEntityReferenceEntityTask.java b/src/main/java/org/openecomp/sparky/synchronizer/task/GetCrossEntityReferenceEntityTask.java deleted file mode 100644 index aaad6c9..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/GetCrossEntityReferenceEntityTask.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.util.function.Supplier; - -import org.openecomp.sparky.dal.NetworkTransaction; -import org.openecomp.sparky.dal.aai.ActiveInventoryDataProvider; -import org.openecomp.sparky.dal.rest.OperationResult; - -/** - * The Class GetCrossEntityReferenceEntityTask. - */ -public class GetCrossEntityReferenceEntityTask implements Supplier<NetworkTransaction> { - - private NetworkTransaction txn; - - private ActiveInventoryDataProvider provider; - - /** - * Instantiates a new gets the cross entity reference entity task. - * - * @param txn the txn - * @param provider the provider - */ - public GetCrossEntityReferenceEntityTask(NetworkTransaction txn, - ActiveInventoryDataProvider provider) { - this.txn = txn; - this.provider = provider; - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public NetworkTransaction get() { - - txn.setTaskAgeInMs(); - - long startTimeInMs = System.currentTimeMillis(); - OperationResult result = null; - try { - result = provider.queryActiveInventoryWithRetries(txn.getLink(), "application/json", 5); - } catch (Exception exc) { - result = new OperationResult(500, - "Caught an exception while trying to resolve link = " + exc.getMessage()); - } finally { - result.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs); - txn.setOperationResult(result); - } - - return txn; - } - -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/PerformActiveInventoryRetrieval.java b/src/main/java/org/openecomp/sparky/synchronizer/task/PerformActiveInventoryRetrieval.java deleted file mode 100644 index 920427e..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/PerformActiveInventoryRetrieval.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.util.Map; -import java.util.function.Supplier; - -import org.openecomp.sparky.dal.NetworkTransaction; -import org.openecomp.sparky.dal.aai.ActiveInventoryDataProvider; -import org.openecomp.sparky.dal.rest.OperationResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; - -/* - * Consider abstraction the tasks into common elemnts, because most of them repeat a generic call - * flow pattern - */ - -/** - * The Class PerformActiveInventoryRetrieval. - */ -public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransaction> { - - private static Logger logger = LoggerFactory.getLogger(PerformActiveInventoryRetrieval.class); - - private NetworkTransaction txn; - private ActiveInventoryDataProvider aaiProvider; - private Map<String, String> contextMap; - - /** - * Instantiates a new perform active inventory retrieval. - * - * @param txn the txn - * @param aaiProvider the aai provider - */ - public PerformActiveInventoryRetrieval(NetworkTransaction txn, - ActiveInventoryDataProvider aaiProvider) { - this.txn = txn; - this.aaiProvider = aaiProvider; - this.contextMap = MDC.getCopyOfContextMap(); - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public NetworkTransaction get() { - - txn.setTaskAgeInMs(); - - long startTimeInMs = System.currentTimeMillis(); - MDC.setContextMap(contextMap); - OperationResult result = null; - try { - // todo: use proper config instead of hard-coding parameters - result = aaiProvider.queryActiveInventoryWithRetries(txn.getLink(), "application/json", 5); - } catch (Exception exc) { - logger.error("Failure to resolve self link from AAI. Error = ", exc); - result = new OperationResult(500, - "Caught an exception while trying to resolve link = " + exc.getMessage()); - } finally { - result.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs); - txn.setOperationResult(result); - } - - return txn; - } - -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchPut.java b/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchPut.java deleted file mode 100644 index f318c9d..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchPut.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.util.Map; -import java.util.function.Supplier; - -import org.openecomp.sparky.dal.NetworkTransaction; -import org.openecomp.sparky.dal.rest.OperationResult; -import org.openecomp.sparky.dal.rest.RestDataProvider; -import org.slf4j.MDC; - -/** - * The Class PerformElasticSearchPut. - */ -public class PerformElasticSearchPut implements Supplier<NetworkTransaction> { - - private RestDataProvider restDataProvider; - private String jsonPayload; - private NetworkTransaction txn; - private Map<String, String> contextMap; - - /** - * Instantiates a new perform elastic search put. - * - * @param jsonPayload the json payload - * @param txn the txn - * @param restDataProvider the rest data provider - */ - public PerformElasticSearchPut(String jsonPayload, NetworkTransaction txn, - RestDataProvider restDataProvider) { - this.jsonPayload = jsonPayload; - this.txn = txn; - this.restDataProvider = restDataProvider; - this.contextMap = MDC.getCopyOfContextMap(); - } - - public PerformElasticSearchPut(String jsonPayload, NetworkTransaction txn, - RestDataProvider restDataProvider, Map<String, String> contextMap) { - this.jsonPayload = jsonPayload; - this.txn = txn; - this.restDataProvider = restDataProvider; - this.contextMap = contextMap; - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public NetworkTransaction get() { - txn.setTaskAgeInMs(); - long startTimeInMs = System.currentTimeMillis(); - MDC.setContextMap(contextMap); - - OperationResult or = restDataProvider.doPut(txn.getLink(), jsonPayload, "application/json"); - - or.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs); - txn.setOperationResult(or); - - return txn; - } -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchRetrieval.java b/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchRetrieval.java deleted file mode 100644 index 17652b4..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchRetrieval.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.util.Map; -import java.util.function.Supplier; - -import org.openecomp.sparky.dal.NetworkTransaction; -import org.openecomp.sparky.dal.rest.OperationResult; -import org.openecomp.sparky.dal.rest.RestDataProvider; -import org.slf4j.MDC; - -/** - * The Class PerformElasticSearchRetrieval. - */ -public class PerformElasticSearchRetrieval implements Supplier<NetworkTransaction> { - - private NetworkTransaction txn; - private RestDataProvider restDataProvider; - private Map<String, String> contextMap; - - /** - * Instantiates a new perform elastic search retrieval. - * - * @param elasticSearchTxn the elastic search txn - * @param restDataProvider the rest data provider - */ - public PerformElasticSearchRetrieval(NetworkTransaction elasticSearchTxn, - RestDataProvider restDataProvider) { - this.txn = elasticSearchTxn; - this.restDataProvider = restDataProvider; - this.contextMap = MDC.getCopyOfContextMap(); - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public NetworkTransaction get() { - MDC.setContextMap(contextMap); - OperationResult or = restDataProvider.doGet(txn.getLink(), "application/json"); - txn.setOperationResult(or); - return txn; - } - -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchUpdate.java b/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchUpdate.java deleted file mode 100644 index 52505a2..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/PerformElasticSearchUpdate.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.util.Map; -import java.util.function.Supplier; - -import org.openecomp.sparky.dal.NetworkTransaction; -import org.openecomp.sparky.dal.elasticsearch.ElasticSearchDataProvider; -import org.openecomp.sparky.dal.rest.OperationResult; -import org.slf4j.MDC; - -/** - * The Class PerformElasticSearchUpdate. - */ -public class PerformElasticSearchUpdate implements Supplier<NetworkTransaction> { - - private ElasticSearchDataProvider esDataProvider; - private NetworkTransaction operationTracker; - private String updatePayload; - private String updateUrl; - private Map<String, String> contextMap; - - /** - * Instantiates a new perform elastic search update. - * - * @param updateUrl the update url - * @param updatePayload the update payload - * @param esDataProvider the es data provider - * @param transactionTracker the transaction tracker - */ - public PerformElasticSearchUpdate(String updateUrl, String updatePayload, - ElasticSearchDataProvider esDataProvider, NetworkTransaction transactionTracker) { - this.updateUrl = updateUrl; - this.updatePayload = updatePayload; - this.esDataProvider = esDataProvider; - this.contextMap = MDC.getCopyOfContextMap(); - this.operationTracker = new NetworkTransaction(); - operationTracker.setEntityType(transactionTracker.getEntityType()); - operationTracker.setDescriptor(transactionTracker.getDescriptor()); - operationTracker.setOperationType(transactionTracker.getOperationType()); - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public NetworkTransaction get() { - operationTracker.setTaskAgeInMs(); - long startTimeInMs = System.currentTimeMillis(); - MDC.setContextMap(contextMap); - OperationResult or = esDataProvider.doBulkOperation(updateUrl, updatePayload); - - or.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs); - operationTracker.setOperationResult(or); - - return operationTracker; - } - -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/PersistOperationResultToDisk.java b/src/main/java/org/openecomp/sparky/synchronizer/task/PersistOperationResultToDisk.java deleted file mode 100644 index c63e6a3..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/PersistOperationResultToDisk.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.io.File; -import java.util.Map; -import java.util.function.Supplier; - -import org.openecomp.cl.api.Logger; -import org.openecomp.sparky.dal.rest.OperationResult; -import org.openecomp.sparky.logging.AaiUiMsgs; -import org.slf4j.MDC; - -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * The Class PersistOperationResultToDisk. - */ -public class PersistOperationResultToDisk implements Supplier<Void> { - - private String fullPath; - private OperationResult dataToStore; - private ObjectMapper mapper; - private Logger logger; - private Map<String, String> contextMap; - - /** - * Instantiates a new persist operation result to disk. - * - * @param fullPath the full path - * @param dataToStore the data to store - * @param mapper the mapper - * @param logger the logger - */ - public PersistOperationResultToDisk(String fullPath, OperationResult dataToStore, - ObjectMapper mapper, Logger logger) { - - this.fullPath = fullPath; - this.mapper = mapper; - this.dataToStore = dataToStore; - this.logger = logger; - this.contextMap = MDC.getCopyOfContextMap(); - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public Void get() { - MDC.setContextMap(contextMap); - File file = new File(fullPath); - if (!file.exists()) { - try { - mapper.writeValue(new File(fullPath), dataToStore); - } catch (Exception exc) { - logger.error(AaiUiMsgs.DISK_DATA_WRITE_IO_ERROR, exc.toString()); - } - } - - return null; - } - - - -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/RetrieveOperationResultFromDisk.java b/src/main/java/org/openecomp/sparky/synchronizer/task/RetrieveOperationResultFromDisk.java deleted file mode 100644 index 3701879..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/RetrieveOperationResultFromDisk.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.function.Supplier; - -import org.openecomp.cl.api.Logger; -import org.openecomp.sparky.dal.rest.OperationResult; -import org.openecomp.sparky.logging.AaiUiMsgs; - -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * The Class RetrieveOperationResultFromDisk. - */ -public class RetrieveOperationResultFromDisk implements Supplier<OperationResult> { - - private String fullPath; - private ObjectMapper mapper; - private Logger logger; - - /** - * Instantiates a new retrieve operation result from disk. - * - * @param fullPath the full path - * @param mapper the mapper - * @param logger the logger - */ - public RetrieveOperationResultFromDisk(String fullPath, ObjectMapper mapper, Logger logger) { - - this.fullPath = fullPath; - this.mapper = mapper; - this.logger = logger; - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public OperationResult get() { - - try { - File file = new File(fullPath); - if (file.exists()) { - if (logger.isDebugEnabled()) { - logger.debug(AaiUiMsgs.WILL_RETRIEVE_TXN, fullPath); - } - - Path path = Paths.get(fullPath); - byte[] byteBuffer = Files.readAllBytes(path); - - OperationResult opResult = mapper.readValue(byteBuffer, OperationResult.class); - - return opResult; - } else { - logger.debug(AaiUiMsgs.FAILED_TO_RESTORE_TXN_FILE_MISSING, fullPath); - } - } catch (IOException exc) { - logger.error(AaiUiMsgs.DISK_CACHE_READ_IO_ERROR, exc.getLocalizedMessage()); - } - return null; - } - -} diff --git a/src/main/java/org/openecomp/sparky/synchronizer/task/StoreDocumentTask.java b/src/main/java/org/openecomp/sparky/synchronizer/task/StoreDocumentTask.java deleted file mode 100644 index 5b7ec00..0000000 --- a/src/main/java/org/openecomp/sparky/synchronizer/task/StoreDocumentTask.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file 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. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.sparky.synchronizer.task; - -import java.util.Map; -import java.util.function.Supplier; - -import org.openecomp.sparky.dal.NetworkTransaction; -import org.openecomp.sparky.dal.rest.OperationResult; -import org.openecomp.sparky.dal.rest.RestDataProvider; -import org.openecomp.sparky.synchronizer.entity.IndexDocument; -import org.slf4j.MDC; - -/** - * The Class StoreDocumentTask. - */ -public class StoreDocumentTask implements Supplier<NetworkTransaction> { - - private IndexDocument doc; - - private NetworkTransaction txn; - - private RestDataProvider esDataProvider; - private Map<String, String> contextMap; - - /** - * Instantiates a new store document task. - * - * @param doc the doc - * @param txn the txn - * @param esDataProvider the es data provider - */ - public StoreDocumentTask(IndexDocument doc, NetworkTransaction txn, - RestDataProvider esDataProvider) { - this.doc = doc; - this.txn = txn; - this.esDataProvider = esDataProvider; - this.contextMap = MDC.getCopyOfContextMap(); - } - - /* (non-Javadoc) - * @see java.util.function.Supplier#get() - */ - @Override - public NetworkTransaction get() { - txn.setTaskAgeInMs(); - - long startTimeInMs = System.currentTimeMillis(); - MDC.setContextMap(contextMap); - OperationResult or = - esDataProvider.doPut(txn.getLink(), doc.getIndexDocumentJson(), "application/json"); - or.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs); - - txn.setOperationResult(or); - - return txn; - } - -} |