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
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP and OpenECOMP are trademarks
21 * and service marks of AT&T Intellectual Property.
23 package org.openecomp.modelloader.service;
25 import java.util.Date;
26 import java.util.Timer;
27 import java.util.TimerTask;
29 import org.openecomp.cl.api.Logger;
30 import org.openecomp.cl.eelf.LoggerFactory;
31 import org.openecomp.modelloader.config.ModelLoaderConfig;
32 import org.openecomp.modelloader.notification.EventCallback;
33 import org.openecomp.sdc.api.IDistributionClient;
34 import org.openecomp.sdc.api.results.IDistributionClientResult;
35 import org.openecomp.sdc.utils.DistributionActionResultEnum;
37 public class SdcConnectionJob extends TimerTask {
38 static Logger logger = LoggerFactory.getInstance().getLogger(SdcConnectionJob.class.getName());
40 private IDistributionClient client;
41 private ModelLoaderConfig config;
42 private EventCallback callback;
45 public SdcConnectionJob(IDistributionClient client,
46 ModelLoaderConfig config,
47 EventCallback callback,
51 this.callback = callback;
58 IDistributionClientResult initResult = client.init(config, callback);
60 if (initResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
61 String errorMsg = "Failed to initialize distribution client: "
62 + initResult.getDistributionMessageResult();
63 logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg);
67 IDistributionClientResult startResult = client.start();
68 if (startResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
69 String errorMsg = "Failed to start distribution client: "
70 + startResult.getDistributionMessageResult();
71 logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg);
75 // Success. Cancel the timer job
77 logger.info(ModelLoaderMsgs.INITIALIZING, "Connection to SDC established");