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.impl;
23 import com.google.common.collect.ImmutableMap;
24 import org.onap.vid.job.Job;
25 import org.onap.vid.job.JobAdapter;
26 import org.onap.vid.job.JobType;
27 import org.onap.vid.model.JobModel;
28 import org.onap.vid.properties.Features;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
31 import org.togglz.core.manager.FeatureManager;
34 import java.util.UUID;
37 public class JobAdapterImpl implements JobAdapter {
39 private final FeatureManager featureManager;
42 public JobAdapterImpl(FeatureManager featureManager) {
43 this.featureManager = featureManager;
48 public JobModel toModel(Job job) {
49 JobModel jobModel = new JobModel();
50 jobModel.setUuid(job.getUuid());
51 jobModel.setStatus(job.getStatus());
52 jobModel.setTemplateId(job.getTemplateId());
57 public Job createServiceInstantiationJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, String testApi, String optimisticUniqueServiceInstanceName, Integer indexInBulk){
58 JobDaoImpl job = createJob(jobType, Job.JobStatus.PENDING , userId);
59 job.setSharedData(new JobSharedData(job.getUuid(), userId, request, testApi));
60 job.setTypeAndData(jobType, ImmutableMap.of(
61 "optimisticUniqueServiceInstanceName", optimisticUniqueServiceInstanceName
63 job.setTemplateId(templateId);
64 job.setIndexInBulk(indexInBulk);
69 public Job createChildJob(JobType jobType, AsyncJobRequest request, JobSharedData parentSharedData, Map<String, Object> jobData, int indexInBulk) {
70 Job.JobStatus jobStatus = featureManager.isActive(Features.FLAG_EXP_CREATE_RESOURCES_IN_PARALLEL) ?
71 Job.JobStatus.CREATING : Job.JobStatus.PENDING_RESOURCE;
72 JobDaoImpl job = createJob(jobType, jobStatus , parentSharedData.getUserId());
73 job.setSharedData(new JobSharedData(job.getUuid(), request, parentSharedData));
74 job.setTypeAndData(jobType, jobData);
75 job.setTemplateId(parentSharedData.jobUuid);
76 job.setIndexInBulk(indexInBulk);
80 protected JobDaoImpl createJob(JobType jobType, Job.JobStatus jobStatus, String userId) {
81 JobDaoImpl job = new JobDaoImpl();
82 job.setTypeAndData(jobType, null);
83 job.setStatus(jobStatus);
84 job.setUuid(UUID.randomUUID());
85 job.setUserId(userId);