2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * 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=========================================================
21 package org.onap.vid.job.command;
23 import com.google.common.collect.ImmutableMap;
24 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.onap.vid.job.*;
26 import org.onap.vid.job.impl.JobSharedData;
27 import org.onap.vid.mso.RestMsoImplementation;
28 import org.onap.vid.mso.RestObject;
29 import org.onap.vid.mso.rest.AsyncRequestStatus;
30 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
31 import org.togglz.core.manager.FeatureManager;
33 import javax.inject.Inject;
36 public abstract class BaseInProgressStatusCommand extends BaseInstantiationCommand implements JobCommand {
37 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BaseInProgressStatusCommand.class);
40 protected AsyncInstantiationBusinessLogic asyncInstantiationBL;
43 protected JobsBrokerService jobsBrokerService;
46 protected JobAdapter jobAdapter;
49 protected RestMsoImplementation restMso;
52 protected FeatureManager featureManager;
55 protected InProgressStatusService inProgressStatusService;
58 protected String requestId;
60 protected String instanceId;
64 public NextCommand call() {
67 Job.JobStatus jobStatus = inProgressStatusService.call(getExpiryChecker(), getSharedData(), requestId);
68 return processJobStatus(jobStatus);
69 } catch (javax.ws.rs.ProcessingException e) {
70 // Retry when we can't connect MSO during getStatus
71 LOGGER.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, will retry: {}", requestId, e, e);
72 return new NextCommand(Job.JobStatus.IN_PROGRESS, this);
73 } catch (InProgressStatusService.BadResponseFromMso e) {
74 return handleFailedMsoResponse(e.getMsoResponse());
76 catch (RuntimeException e) {
77 LOGGER.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, stopping: {}", requestId, e, e);
78 return new NextCommand(Job.JobStatus.STOPPED, this);
82 protected abstract ExpiryChecker getExpiryChecker();
84 abstract NextCommand processJobStatus(Job.JobStatus jobStatus);
86 private NextCommand handleFailedMsoResponse(RestObject<AsyncRequestStatus> msoResponse) {
87 inProgressStatusService.handleFailedMsoResponse(getSharedData().getJobUuid(), requestId, msoResponse);
88 return new NextCommand(Job.JobStatus.IN_PROGRESS, this);
92 public BaseInProgressStatusCommand init(JobSharedData sharedData, Map<String, Object> commandData) {
93 return init(sharedData, (String) commandData.get("requestId"), (String) commandData.get("instanceId"));
97 protected BaseInProgressStatusCommand init(JobSharedData sharedData,
101 this.requestId = requestId;
102 this.instanceId = instanceId;
107 public Map<String, Object> getData() {
108 return ImmutableMap.of(
109 "requestId", requestId,
110 "instanceId", instanceId