2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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 package org.onap.aai.modelloader.service;
23 import java.util.Date;
24 import java.util.Timer;
25 import java.util.TimerTask;
27 import org.onap.aai.modelloader.config.ModelLoaderConfig;
28 import org.onap.aai.modelloader.notification.EventCallback;
29 import org.onap.aai.cl.api.Logger;
30 import org.onap.aai.cl.eelf.LoggerFactory;
31 import org.openecomp.sdc.api.IDistributionClient;
32 import org.openecomp.sdc.api.results.IDistributionClientResult;
33 import org.openecomp.sdc.utils.DistributionActionResultEnum;
35 public class SdcConnectionJob extends TimerTask {
36 static Logger logger = LoggerFactory.getInstance().getLogger(SdcConnectionJob.class.getName());
38 private IDistributionClient client;
39 private ModelLoaderConfig config;
40 private EventCallback callback;
43 public SdcConnectionJob(IDistributionClient client,
44 ModelLoaderConfig config,
45 EventCallback callback,
49 this.callback = callback;
56 IDistributionClientResult initResult = client.init(config, callback);
58 if (initResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
59 String errorMsg = "Failed to initialize distribution client: "
60 + initResult.getDistributionMessageResult();
61 logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg);
65 IDistributionClientResult startResult = client.start();
66 if (startResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
67 String errorMsg = "Failed to start distribution client: "
68 + startResult.getDistributionMessageResult();
69 logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg);
73 // Success. Cancel the timer job
75 logger.info(ModelLoaderMsgs.INITIALIZING, "Connection to SDC established");