30b34aeeb6b76d926907b460e12b0aa617ea7713
[appc.git] / appc-sdc-listener / appc-sdc-listener-bundle / src / main / java / org / onap / appc / sdc / artifacts / impl / ConfigArtifactProcessor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.appc.sdc.artifacts.impl;
24
25 import java.net.MalformedURLException;
26 import java.net.URI;
27 import org.onap.appc.adapter.message.EventSender;
28 import org.onap.appc.exceptions.APPCException;
29 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
30 import org.onap.appc.sdc.listener.ProviderOperations;
31 import org.onap.appc.sdc.listener.ProviderResponse;
32 import org.onap.appc.sdc.listener.Util;
33 import org.onap.sdc.api.IDistributionClient;
34 import org.onap.sdc.api.notification.IArtifactInfo;
35 import org.onap.sdc.api.notification.INotificationData;
36 import org.onap.sdc.api.notification.IResourceInstance;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
39
40 /**
41  * Artifact processor for config artifact type
42  */
43 public class ConfigArtifactProcessor extends AbstractArtifactProcessor {
44
45     private final EELFLogger logger = EELFManager.getInstance().getLogger(ConfigArtifactProcessor.class);
46
47     /**
48      * returns an instance of ConfigArtifactProcessor
49      *
50      * @param client an instance of IDistributionClient
51      * @param eventSender an instance of EventSender
52      * @param notification an instance of INotificationData
53      * @param resource an instance of IResourceInstance
54      * @param artifact an instance of IArtifactInfo
55      * @param storeUri an instance of URI
56      */
57     public ConfigArtifactProcessor(IDistributionClient client, EventSender eventSender, INotificationData notification,
58             IResourceInstance resource, IArtifactInfo artifact, URI storeUri) {
59         super(client, eventSender, notification, resource, artifact, storeUri);
60     }
61
62     @Override
63     public void processArtifact(SDCArtifact artifact) throws APPCException {
64         String postData =
65                 Util.toSdcStoreDocumentInput(notification, resource, super.artifact, artifact.getArtifactContent());
66         logger.debug("ConfigArtifactProcessor::processArtifact::postData=" + postData);
67         try {
68             if (null != storeUri) {
69                 logger.debug("ConfigArtifactProcessor::processArtifact::URI is" + storeUri.toString());
70                 ProviderResponse result = ProviderOperations.post(storeUri.toURL(), postData, null);
71                 if (result.getStatus() == 200) {
72                     logger.debug("ConfigArtifactProcessor::processArtifact::post request success!!");
73                     Util.parseResponse(result.getBody());
74                 } else {
75                     logger.debug("ConfigArtifactProcessor::processArtifact()::post request failed!! Returned :"
76                             + result.getStatus() + "-Result body- " + result.getBody());
77                     throw new APPCException(
78                             "ConfigArtifactProcessor::processArtifact: Invalid status retrurned from post "
79                                     + result.getStatus());
80                 }
81             } else {
82                 logger.error("ConfigArtifactProcessor::processArtifact, storeURI is null");
83             }
84         } catch (MalformedURLException | APPCException e) {
85             logger.error("Error processing artifact : " + this.artifact.toString(), e);
86             throw new APPCException(e.getMessage(), e);
87         }
88     }
89 }