2 * ============LICENSE_START=======================================================
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 is a trademark and service mark of AT&T Intellectual Property.
24 package org.openecomp.modelloader.service;
26 import java.util.Date;
27 import java.util.Timer;
28 import java.util.TimerTask;
30 import org.openecomp.cl.api.Logger;
31 import org.openecomp.cl.eelf.LoggerFactory;
32 import org.openecomp.modelloader.config.ModelLoaderConfig;
33 import org.openecomp.modelloader.notification.EventCallback;
34 import org.openecomp.sdc.api.IDistributionClient;
35 import org.openecomp.sdc.api.results.IDistributionClientResult;
36 import org.openecomp.sdc.utils.DistributionActionResultEnum;
38 public class SdcConnectionJob extends TimerTask {
39 static Logger logger = LoggerFactory.getInstance().getLogger(SdcConnectionJob.class.getName());
41 private IDistributionClient client;
42 private ModelLoaderConfig config;
43 private EventCallback callback;
46 public SdcConnectionJob(IDistributionClient client,
47 ModelLoaderConfig config,
48 EventCallback callback,
52 this.callback = callback;
59 IDistributionClientResult initResult = client.init(config, callback);
61 if (initResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
62 String errorMsg = "Failed to initialize distribution client: "
63 + initResult.getDistributionMessageResult();
64 logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg);
68 IDistributionClientResult startResult = client.start();
69 if (startResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
70 String errorMsg = "Failed to start distribution client: "
71 + startResult.getDistributionMessageResult();
72 logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg);
76 // Success. Cancel the timer job
78 logger.info(ModelLoaderMsgs.INITIALIZING, "Connection to SDC established");