`
rogerhunt
  • 浏览: 59653 次
  • 性别: Icon_minigender_1
  • 来自: 新加坡
社区版块
存档分类
最新评论

ValidationMessageMapping

阅读更多
package com.savvis.spirits.domain;

import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

@Entity
@Table(name = "validation_message")
public class ValidationMessageMapping implements java.io.Serializable {

    private Integer id;
    private String mwCase;
    private String mwType;
    private String message;
    private String apiMessage;
    private Integer moduleCode;
    private Integer categorymoduleCode;
    private Integer componentmoduleCode;
    private Integer errorCode;
    private Integer httpCode;
    private String status;

    public ValidationMessageMapping() {
    }

    public ValidationMessageMapping(Integer id, String mwCase, String apiMessage, String message, Integer moduleCode, Integer httpCode, String mwType, Integer categorymoduleCode, Integer componentmoduleCode, String status) {
        this.id = id;
        this.mwCase = mwCase;
        this.apiMessage = apiMessage;
        this.message = message;
        this.moduleCode = moduleCode;
        this.httpCode = httpCode;
        this.mwType = mwType;
        this.categorymoduleCode = categorymoduleCode;
        this.componentmoduleCode = componentmoduleCode;
        this.status = status;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "mw_case", length = 200, nullable = false)
    public String getMwCase() {
        return mwCase;
    }

    public void setMwCase(String mwCase) {
        this.mwCase = mwCase;
    }

    @Column(name = "mw_type", length = 200)
    public String getMwType() {
        return mwType;
    }

    public void setMwType(String mwType) {
        this.mwType = mwType;
    }

    @Column(name = "message", nullable = false)
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Column(name = "api_message")
    public String getApiMessage() {
        return apiMessage;
    }

    public void setApiMessage(String apiMessage) {
        this.apiMessage = apiMessage;
    }

    @Column(name = "module_code", length = 10, nullable = false)
    public Integer getModuleCode() {
        return moduleCode;
    }

    public void setModuleCode(Integer moduleCode) {
        this.moduleCode = moduleCode;
    }

    @Column(name = "category_code", length = 10, nullable = false)
    public Integer getCategorymoduleCode() {
        return categorymoduleCode;
    }

    public void setCategorymoduleCode(Integer categorymoduleCode) {
        this.categorymoduleCode = categorymoduleCode;
    }

    @Column(name = "component_code", length = 10, nullable = false)
    public Integer getComponentmoduleCode() {
        return componentmoduleCode;
    }

    public void setComponentmoduleCode(Integer componentmoduleCode) {
        this.componentmoduleCode = componentmoduleCode;
    }

    @Column(name = "error_code", length = 10, nullable = false)
    public Integer geterrorCode() {
        return errorCode;
    }

    public void seterrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    @Column(name = "http_code", length = 10)
    public Integer gethttpCode() {
        return httpCode;
    }

    public void sethttpCode(Integer httpCode) {
        this.httpCode = httpCode;
    }

    @Column(name = "status", length = 50)
    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @Override
    public String toString() {
        return "ValidationMessageMapping{" +
                "id=" + id +
                ", mwCase='" + mwCase + '\'' +
                ", message='" + message + '\'' +
                ", apiMessage='" + apiMessage + '\'' +
                ", modulemoduleCode=" + moduleCode +
                ", httpCode=" + httpCode +
                ", categorymoduleCode=" + categorymoduleCode +
                ", componentmoduleCode=" + componentmoduleCode +
                ", errorCode=" + errorCode +
                ", mwType='" + mwType + '\'' +
                '}';
    }
}



********************************************

package com.savvis.spirits.services.queue.process;

import com.savvis.spirits.businessmodel.servicedesign.Compute;
import com.savvis.spirits.businessmodel.servicedesign.Computes;
import com.savvis.spirits.businessmodel.servicedesign.Drive;
import com.savvis.spirits.businessmodel.servicedesign.VPDCServiceDesign;
import com.savvis.spirits.common.exceptions.SystemException;
import com.savvis.spirits.common.utils.MWConstants;
import com.savvis.spirits.common.utils.MWUtil;
import com.savvis.spirits.dao.VpdcDetailDAO;
import com.savvis.spirits.dao.VpdcQueueProcessDAO;
import com.savvis.spirits.dao.VpdcQueueProcessResultDAO;
import com.savvis.spirits.domain.*;
import com.savvis.spirits.domain.enums.OperationEnum;
import com.savvis.spirits.domain.enums.VpdcQueueProcessStatusEnum;
import com.savvis.spirits.integration.schemas.queueprocess.*;
import com.savvis.spirits.services.xml.parser.ObjectConverter;
import com.savvis.spirits.vcloud.header.VCloudHeader;
import com.savvis.spirits.vcloud.header.VCloudHeaderHolder;
import com.savvis.spirits.vcloud.header.VCloudUser;
import com.savvis.spirits.vcloud.helper.VpdcTemplateHelper;
import com.savvis.spirits.vcloud.proxy.RestProxyAuthenticationService;
import com.savvis.spirits.vcloud.wrapper.VCloudHelper;
import com.savvis.spirits.yfilesconverter.YFilesConverter;
import com.savvis.spirits.yfilesconverter.dataobjects.*;
import java.util.*;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.stereotype.Service;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import java.io.*;

/**
* Created by IntelliJ IDEA.
* User: ramesh.rajaram
* Date: Jan 12, 2011
* Time: 1:36:38 PM
* To change this template use File | Settings | File Templates.
*/

@Service("vpdcQueueProcessPreEngine")
public class VPDCQueueProcessPreEngine {

    private static final Logger log = Logger.getLogger(VPDCQueueProcessPreEngine.class);

    @Autowired
    VpdcDetailDAO vpdcDetailDAO;
    @Autowired
    private ObjectConverter objectConverter;
    @Autowired
    VpdcQueueProcessDAO vpdcQueueProcessDAO;
    @Autowired
    VpdcQueueProcessResultDAO vpdcQueueProcessResultDAO;
    @Autowired
    private RestProxyAuthenticationService restProxyAuthenticationService;
    @Autowired
    @Qualifier("marshaller")
    protected Jaxb2Marshaller marshaller;
    @Autowired
    private VpdcTemplateHelper vpdcTemplateHelper;

    public VPDCQueueProcessPreEngine() {

    }

    public VPDCQueueProcessPreEngine(Object inputRequest, String vpdcCompType) {
        addToQueue(inputRequest, vpdcCompType);
    }

    public TaskInfo addToQueue(Object inputRequest, String vpdcCompType) {

        VCloudHeader vCloudHeader = VCloudHeaderHolder.getVcloudHeader();
        VCloudUser vCloudUser = restProxyAuthenticationService.getVCloudUser(vCloudHeader.getToken());

        //insert record to VPDCQueueProcess
        VpdcQueueProcess vpdcQueueProcess = new VpdcQueueProcess();
        vpdcQueueProcess.setCreatedBy(vCloudUser.getUserId());
        vpdcQueueProcess.setCreateTime(new Date());
        vpdcQueueProcess.setProcessType(vpdcCompType);
        vpdcQueueProcess.setStatus(VpdcQueueProcessStatusEnum.QUEUED);
        vpdcQueueProcess.setInput(convertRequestResponseToString(inputRequest));
        TaskInfo taskInfo = new TaskInfo();
        taskInfo.setProcessType(vpdcCompType);
        taskInfo.setTaskStatus(VpdcQueueProcessStatusEnum.QUEUED.name());

        if (inputRequest instanceof VMOperationRequest) {

            putVMOperationRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof ChangeTemplateRequest) {

            putChangeTemplateRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof CloneVCloudTemplateRequest) {

            putCloneVCloudTemplateRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof SaveVCloudTemplateRequest) {

            putSaveVCloudTemplateRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof InstantiateVCloudTemplateRequest) {

            putInstantiateVCloudTemplateRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof FirewallRequest) {

            putFWOperationRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof CloneVCloudvAppRequest) {

            putCloneVCloudvAppRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof CloneVCloudMultiplevAppRequest) {

            putCloneVCloudMultiplevAppRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof DetachVCloudVMDKRequest) {

            putDetachVMDKRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof DeleteVCloudVMDKRequest) {

            putDeleteVMDKRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof AttachVCloudVMDKRequest) {

            putAttachVMDKRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        } else if (inputRequest instanceof CloneVCloudVMDKRequest) {

            putCloneVMDKRequestInQueue(inputRequest, vpdcQueueProcess, taskInfo);

        }

        vpdcQueueProcess.setOutput(convertRequestResponseToString(new JAXBElement<TaskInfo>(new QName("http://www.savvis.com/spirits/services/schemas/queueprocess/types", "TaskInfo"), TaskInfo.class, taskInfo)));
        vpdcQueueProcessDAO.update(vpdcQueueProcess);

        return taskInfo;
    }

    private void putVMOperationRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        YFilesConverter yFilesConverter = new YFilesConverter();
        int nextGuiId = 0;
        VMOperationRequest request = (VMOperationRequest) inputRequest;
        vpdcQueueProcess.setBillingSiteId(request.getBillingsiteId());
        vpdcQueueProcess.setVpdcId(request.getVpdcId());
        vpdcQueueProcess.setProcessName("VMOperation");
        vpdcQueueProcess.setProcessIdentifier("01");
        VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getVpdcId());
        if (null != vpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(vpdcDetail.getVpdcName());

            if (MWUtil.isNotEmptyString(vpdcDetail.getTransientYfiles())) {     // todo for what
                yFilesConverter.loadGraphML(new ByteArrayInputStream(vpdcDetail.getTransientYfiles().getBytes()));
                nextGuiId = yFilesConverter.getNewServerGuiId();
                vpdcDetail.setTransientYfiles(yFilesConverter.getGraphML());
            } else {
                yFilesConverter.loadGraphML(new ByteArrayInputStream(vpdcDetail.getGuiXml().getBytes()));
                nextGuiId = yFilesConverter.getNewServerGuiId();
                vpdcQueueProcess.setGuiXml(yFilesConverter.getGraphML());
            }
            vpdcDetailDAO.update(vpdcDetail);
        }
        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(vpdcQueueProcess.getProcessId() + "");
        taskInfo.setOrgId(request.getBillingsiteId());
        taskInfo.setOwnerId(request.getVpdcId() + "");
        taskInfo.setProcessName("VMOperation");
        for (VCloudCompute vCloudCompute : request.getVcloudComputes().getCompute()) {
            TaskResultInfo taskResultInfo = new TaskResultInfo();
            taskResultInfo.setResultReference(vCloudCompute.getCustHostName());
            taskResultInfo.setResultStatus("queued");
            VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
            vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
            vpdcQueueProcessResult.setProcessResultName(vCloudCompute.getCustHostName());
            vpdcQueueProcessResult.setProcessResultStatus("queued");
            if (VMAction.ADD.equals(vCloudCompute.getAction())) {
                vpdcQueueProcessResult.setProcessResultId(nextGuiId);
                taskResultInfo.setResultReferenceId(nextGuiId + "");
                nextGuiId++;
            } else {
                vpdcQueueProcessResult.setProcessResultId(Integer.parseInt(vCloudCompute.getGuiId()));
                taskResultInfo.setResultReferenceId(vCloudCompute.getGuiId());
            }
            vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
            taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
            taskResultInfoList.add(taskResultInfo);
        }
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putChangeTemplateRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        ChangeTemplateRequest request = (ChangeTemplateRequest) inputRequest;
        vpdcQueueProcess.setBillingSiteId(request.getBillingSiteId());
        vpdcQueueProcess.setVpdcId(request.getVpdcId());
        vpdcQueueProcess.setProcessName("ChangeTemplate");
        vpdcQueueProcess.setProcessIdentifier("04");
        VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getVpdcId());
        if (null != vpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(vpdcDetail.getVpdcName());

        }
        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(vpdcQueueProcess.getProcessId() + "");
        taskInfo.setOrgId(request.getBillingSiteId());
        taskInfo.setOwnerId(request.getVpdcId() + "");
        taskInfo.setProcessName("ChangeTemplate");
        if (null != request.getTemplate()) {
            TaskResultInfo taskResultInfo = new TaskResultInfo();
            taskResultInfo.setResultReference(request.getTemplate().getVAppTemplateCustHostName());
            taskResultInfo.setResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
            VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
            vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
            vpdcQueueProcessResult.setProcessResultName(request.getTemplate().getVAppTemplateCustHostName());
            vpdcQueueProcessResult.setProcessResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
            vpdcQueueProcessResult.setProcessResultId(request.getTemplate().getTemplateId());
            taskResultInfo.setResultReferenceId(request.getTemplate().getTemplateId() + "");

            vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
            taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
            taskResultInfoList.add(taskResultInfo);
        }
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putCloneVCloudTemplateRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        CloneVCloudTemplateRequest request = (CloneVCloudTemplateRequest) inputRequest;

        vpdcQueueProcess.setProcessName("CloneVCloudTemplate");
        vpdcQueueProcess.setProcessIdentifier("04");
        VpdcDetail repoVpdcDetail = vpdcTemplateHelper.validateSourceAndTargetVpdc(request.getSourceVpdcId(), request.getTargetVpdcId());
        if (null != repoVpdcDetail) {
            vpdcQueueProcess.setBillingSiteId(repoVpdcDetail.getVpdc().getBillingsiteId());
            vpdcQueueProcess.setVpdcId(repoVpdcDetail.getVpdc().getId());
            taskInfo.setOrgId(repoVpdcDetail.getVpdc().getBillingsiteId());
            taskInfo.setOwnerId(repoVpdcDetail.getVpdc().getId() + "");
        }

        VpdcDetail targetVpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getTargetVpdcId());
        if (null != targetVpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(targetVpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(targetVpdcDetail.getVpdcName());
        }

        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(vpdcQueueProcess.getProcessId() + "");
        taskInfo.setProcessName("CloneVCloudTemplate");
        TaskResultInfo taskResultInfo = new TaskResultInfo();
        taskResultInfo.setResultReference(request.getTemplateName());
        taskResultInfo.setResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
        vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
        vpdcQueueProcessResult.setProcessResultName(request.getTemplateName());
        vpdcQueueProcessResult.setProcessResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        //todo
        vpdcQueueProcessResult.setProcessResultId(0);
        taskResultInfo.setResultReferenceId("");

        vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
        taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
        taskResultInfoList.add(taskResultInfo);
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putSaveVCloudTemplateRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        SaveVCloudTemplateRequest request = (SaveVCloudTemplateRequest) inputRequest;

        vpdcQueueProcess.setProcessName("SaveVCloudTemplate");
        vpdcQueueProcess.setProcessIdentifier("04");
        VpdcDetail repoVpdcDetail = vpdcTemplateHelper.validateSourceAndTargetVpdc(request.getSourceVpdcId(), request.getTargetVpdcId());
        if (null != repoVpdcDetail) {
            vpdcQueueProcess.setBillingSiteId(repoVpdcDetail.getVpdc().getBillingsiteId());
            vpdcQueueProcess.setVpdcId(repoVpdcDetail.getVpdc().getId());
            taskInfo.setOrgId(repoVpdcDetail.getVpdc().getBillingsiteId());
            taskInfo.setOwnerId(repoVpdcDetail.getVpdc().getId() + "");
        }

        VpdcDetail targetVpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getTargetVpdcId());
        if (null != targetVpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(targetVpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(targetVpdcDetail.getVpdcName());
        }

        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(vpdcQueueProcess.getProcessId() + "");
        taskInfo.setProcessName("SaveVCloudTemplate");
        TaskResultInfo taskResultInfo = new TaskResultInfo();
        taskResultInfo.setResultReference(request.getTemplateName());
        taskResultInfo.setResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
        vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
        vpdcQueueProcessResult.setProcessResultName(request.getTemplateName());
        vpdcQueueProcessResult.setProcessResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        //todo
        vpdcQueueProcessResult.setProcessResultId(0);
        taskResultInfo.setResultReferenceId("");

        vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
        taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
        taskResultInfoList.add(taskResultInfo);
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putInstantiateVCloudTemplateRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        InstantiateVCloudTemplateRequest request = (InstantiateVCloudTemplateRequest) inputRequest;
        List<InstantiateTemplateInfo> templateInfoListFromVCloud = request.getInstantiateTemplateList();
        vpdcQueueProcess.setProcessName("InstantiateVCloudTemplate");
        vpdcQueueProcess.setProcessIdentifier("04");

        int targetVpdcId = request.getInstantiateTemplateList().get(0).getTargetVpdcId();
        int sourceVpdcId = request.getInstantiateTemplateList().get(0).getSourceVpdcId();

        VpdcDetail repoVpdcDetail = vpdcTemplateHelper.validateSourceAndTargetVpdc(sourceVpdcId, targetVpdcId);
        if (null != repoVpdcDetail) {
            vpdcQueueProcess.setBillingSiteId(repoVpdcDetail.getVpdc().getBillingsiteId());
            vpdcQueueProcess.setVpdcId(repoVpdcDetail.getVpdc().getId());
            taskInfo.setOrgId(repoVpdcDetail.getVpdc().getBillingsiteId());
            taskInfo.setOwnerId(repoVpdcDetail.getVpdc().getId() + "");
        }

        YFilesConverter yFilesConverter = new YFilesConverter();
        int nextGuiId = 0;
        VpdcDetail targetVpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(targetVpdcId);
        if (null != targetVpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(targetVpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(targetVpdcDetail.getVpdcName());

            if (MWUtil.isNotEmptyString(targetVpdcDetail.getTransientYfiles())) {
                yFilesConverter.loadGraphML(new ByteArrayInputStream(targetVpdcDetail.getTransientYfiles().getBytes()));
                nextGuiId = yFilesConverter.getNewServerGuiId();
                targetVpdcDetail.setTransientYfiles(yFilesConverter.getGraphML());
            } else {
                yFilesConverter.loadGraphML(new ByteArrayInputStream(targetVpdcDetail.getGuiXml().getBytes()));
                nextGuiId = yFilesConverter.getNewServerGuiId();
                targetVpdcDetail.setGuiXml(yFilesConverter.getGraphML());
            }
            vpdcDetailDAO.update(targetVpdcDetail);
        }

        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(vpdcQueueProcess.getProcessId() + "");
        taskInfo.setProcessName("InstantiateVCloudTemplate");
        for (InstantiateTemplateInfo templateInfoFromVCloud : templateInfoListFromVCloud) {
            TaskResultInfo taskResultInfo = new TaskResultInfo();
            taskResultInfo.setResultReference(templateInfoFromVCloud.getTargetComputeName());
            taskResultInfo.setResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
            VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
            vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
            vpdcQueueProcessResult.setProcessResultName(templateInfoFromVCloud.getTargetComputeName());
            vpdcQueueProcessResult.setProcessResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());

            vpdcQueueProcessResult.setProcessResultId(nextGuiId);
            taskResultInfo.setResultReferenceId(nextGuiId + "");
            nextGuiId++;

            vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
            taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
            taskResultInfoList.add(taskResultInfo);
        }
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putCloneVCloudvAppRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {

        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        YFilesConverter yFilesConverter = new YFilesConverter();
        int nextGuiId = 0;
        CloneVCloudvAppRequest request = (CloneVCloudvAppRequest) inputRequest;
        vpdcQueueProcess.setBillingSiteId(request.getSourceBillingSiteid());
        vpdcQueueProcess.setVpdcId(request.getSourceVpdcId());
        vpdcQueueProcess.setProcessName("CloneVCloudvApp");
        vpdcQueueProcess.setProcessIdentifier("04");
        VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getSourceVpdcId());
        if (null != vpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(vpdcDetail.getVpdcName());
            setGuiXML(vpdcDetail, vpdcQueueProcess, request);

            if (MWUtil.isNotEmptyString(vpdcDetail.getTransientYfiles())) {
                yFilesConverter.loadGraphML(new ByteArrayInputStream(vpdcDetail.getTransientYfiles().getBytes()));
                nextGuiId = yFilesConverter.getNewServerGuiId();
                vpdcDetail.setTransientYfiles(yFilesConverter.getGraphML());
            } else {
                yFilesConverter.loadGraphML(new ByteArrayInputStream(vpdcDetail.getGuiXml().getBytes()));
                nextGuiId = yFilesConverter.getNewServerGuiId();
                vpdcQueueProcess.setGuiXml(yFilesConverter.getGraphML());
            }
            vpdcDetailDAO.update(vpdcDetail);
        }
        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(vpdcQueueProcess.getProcessId() + "");
        taskInfo.setOrgId(request.getTargetBillingSiteid());
        taskInfo.setOwnerId(request.getTargetVpdcId() + "");
        taskInfo.setProcessName("CloneVCloudvApp");
        TaskResultInfo taskResultInfo = new TaskResultInfo();
        taskResultInfo.setResultStatus("queued");
        VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
        vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
        vpdcQueueProcessResult.setProcessResultStatus("queued");
        vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
        taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
        taskResultInfoList.add(taskResultInfo);
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putCloneVCloudMultiplevAppRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        YFilesConverter yFilesConverter = new YFilesConverter();
        int nextGuiId = 0;
        CloneVCloudMultiplevAppRequest request = (CloneVCloudMultiplevAppRequest) inputRequest;
        List<CloneVCloudMultiplevAppsInfo> cloneVCloudMultiplevAppsInfoList = request.getTargetvApps();
        for (int i = 0; i < cloneVCloudMultiplevAppsInfoList.size(); i++) {
            vpdcQueueProcess.setBillingSiteId(cloneVCloudMultiplevAppsInfoList.get(i).getSourceBillingSiteid());
            vpdcQueueProcess.setVpdcId(cloneVCloudMultiplevAppsInfoList.get(i).getSourceVpdcId());
            vpdcQueueProcess.setProcessName("CloneVCloudMultiplevApp");
            vpdcQueueProcess.setProcessIdentifier("05");
            VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(cloneVCloudMultiplevAppsInfoList.get(i).getSourceVpdcId());
            if (null != vpdcDetail) {
                vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
                taskInfo.setOwnerReference(vpdcDetail.getVpdcName());
                setGuiXML(vpdcDetail, vpdcQueueProcess, request);

                if (MWUtil.isNotEmptyString(vpdcDetail.getTransientYfiles())) {
                    yFilesConverter.loadGraphML(new ByteArrayInputStream(vpdcDetail.getTransientYfiles().getBytes()));
                    nextGuiId = yFilesConverter.getNewServerGuiId();
                    vpdcDetail.setTransientYfiles(yFilesConverter.getGraphML());
                } else {
                    yFilesConverter.loadGraphML(new ByteArrayInputStream(vpdcDetail.getGuiXml().getBytes()));
                    nextGuiId = yFilesConverter.getNewServerGuiId();
                    vpdcQueueProcess.setGuiXml(yFilesConverter.getGraphML());
                }
                vpdcDetailDAO.update(vpdcDetail);
            }
            vpdcQueueProcessDAO.save(vpdcQueueProcess);
            taskInfo.setProcessId(vpdcQueueProcess.getProcessId() + "");
            taskInfo.setOrgId(cloneVCloudMultiplevAppsInfoList.get(i).getTargetBillingSiteid());
            taskInfo.setOwnerId(cloneVCloudMultiplevAppsInfoList.get(i).getTargetVpdcId() + "");
            taskInfo.setProcessName("CloneVCloudMultiplevApp");
            TaskResultInfo taskResultInfo = new TaskResultInfo();
            taskResultInfo.setResultStatus("queued");
            VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
            vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
            vpdcQueueProcessResult.setProcessResultStatus("queued");
            vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
            taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
            taskResultInfoList.add(taskResultInfo);
            taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
        }
    }

    /**
     * Method convertRequestResponseToString ...
     *
     * @param request of type Object
     * @return String
     */
    public String convertRequestResponseToString(Object request) {
        StringBuilder design = new StringBuilder();
        try {
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            Result result = new StreamResult(outStream);
            marshaller.marshal(request, result);

            ByteArrayInputStream metaDataInput = new ByteArrayInputStream(outStream.toByteArray());
            InputStreamReader reader = new InputStreamReader(metaDataInput);
            BufferedReader bReader = new BufferedReader(reader);
            String readLine = "";
            while ((readLine = bReader.readLine()) != null) {
                design.append(readLine).append("\n");
            }
        } catch (IOException ex) {
            log.error("IOException occured in VPDCQueueProcessPreEngine.convertRequestResponseToString:" + ex.getMessage(), ex);
        } catch (Exception ex) {
            log.error("Exception occured in VPDCQueueProcessPreEngine.convertRequestResponseToString:" + ex.getMessage(), ex);
        }
        return design.toString();
    }

    private void putFWOperationRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        YFilesConverter yFilesConverter = new YFilesConverter();
        FirewallRequest request = (FirewallRequest) inputRequest;
        vpdcQueueProcess.setBillingSiteId(request.getBillingsiteId());
        vpdcQueueProcess.setVpdcId(request.getVpdcId());
        vpdcQueueProcess.setProcessName("FWOperation");
        vpdcQueueProcess.setProcessIdentifier("03");
        VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getVpdcId());
        if (null != vpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(vpdcDetail.getVpdcName());
            setGuiXML(vpdcDetail, vpdcQueueProcess, request);
        }
        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(vpdcQueueProcess.getProcessId() + "");
        taskInfo.setOrgId(request.getBillingsiteId());
        taskInfo.setOwnerId(request.getVpdcId() + "");
        if (null != request.getPfwRules().getPfwRules() && request.getPfwRules().getPfwRules().size() > 0) {
            taskInfo.setProcessName("PFWOperation");
            for (VCloudFirewallRule vCloudFirewallRule : request.getPfwRules().getPfwRules()) {
                TaskResultInfo taskResultInfo = new TaskResultInfo();
                taskResultInfo.setResultReference("");
                taskResultInfo.setResultStatus("queued");
                VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
                vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
                vpdcQueueProcessResult.setProcessResultName("");
                vpdcQueueProcessResult.setProcessResultStatus("queued");
                vpdcQueueProcessResult.setProcessResultId(0);
                vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
                taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
                taskResultInfoList.add(taskResultInfo);
            }
        }
        if (null != request.getPfwRules().getPfwRules() && request.getStwfRules().getStwfRules().size() > 0) {
            taskInfo.setProcessName("STFWOperation");
            for (VCloudFirewallRule vCloudFirewallRule : request.getStwfRules().getStwfRules()) {
                TaskResultInfo taskResultInfo = new TaskResultInfo();
                taskResultInfo.setResultReference("");
                taskResultInfo.setResultStatus("queued");
                VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
                vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
                vpdcQueueProcessResult.setProcessResultName("");
                vpdcQueueProcessResult.setProcessResultStatus("queued");
                vpdcQueueProcessResult.setProcessResultId(0);
                vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
                taskResultInfo.setResultId(vpdcQueueProcessResult.getId() + "");
                taskResultInfoList.add(taskResultInfo);
            }
        }
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void setGuiXML(VpdcDetail vpdcDetail, VpdcQueueProcess vpdcQueueProcess, CloneVCloudMultiplevAppRequest request) {

    }

    private void setGuiXML(VpdcDetail vpdcDetail, VpdcQueueProcess vpdcQueueProcess, CloneVCloudvAppRequest request) {

        migrationDHCPInfo(vpdcDetail, vpdcQueueProcess, request.getSourceVpdcId());

    }

    private void migrationDHCPInfo(VpdcDetail vpdcDetail, VpdcQueueProcess vpdcQueueProcess, int VpdcId) {
        Map<Integer, String[]> cloneVMInfo = getClonedVMInfo(vpdcDetail.getId(), VpdcId);
        List<Integer> guiIdList = new ArrayList<Integer>();
        String apiName = Thread.currentThread().getStackTrace()[1].getMethodName();
        String vpdcFinalXML = vpdcDetail.getDesignFinalXml().replaceAll("(\r\n|\r|\n|\n\r)", "");
        VPDCServiceDesign vpdcServiceDesign = objectConverter.convertStringToDesign(vpdcFinalXML);
        // retrieve a list of VMs defined inside yfiles
        Computes computes = vpdcServiceDesign.getComputes();
        for (Compute compute : computes.getCompute()) {
            guiIdList.add(compute.getGuiId());
            if (null != cloneVMInfo.get(compute.getGuiId()) && MWConstants.TRUE.equalsIgnoreCase(vpdcDetail.getVpdc().getUseDhcpForCloneTemplate())) {
                compute.setDhcp(true);
            } else {
                compute.setDhcp(false);
//                compute.sets
            }
        }
         if (MWUtil.isNotEmptyString(vpdcDetail.getGuiXml())) {
        YFilesConverter yFilesConverter = new YFilesConverter();
        yFilesConverter.loadGraphML(new ByteArrayInputStream(vpdcDetail.getGuiXml().getBytes()));
        VPDCSpec vpdcSpec = yFilesConverter.getVPDCSpec();
        List<ServerDataObject> serverList = vpdcSpec.getServers();
        for (ServerDataObject vm : serverList) {
            if (guiIdList.contains(vm.getGuiId())) {
                if (null != cloneVMInfo.get(vm.getGuiId()) && MWConstants.TRUE.equalsIgnoreCase(vpdcDetail.getVpdc().getUseDhcpForCloneTemplate())) {
                    vm.setDHCP(true);
                } else {
                    vm.setDHCP(false);
                }
                yFilesConverter.updateCustomObject(vm);
            }
        }
            vpdcQueueProcess.setGuiXml(yFilesConverter.getGraphML());
         }
    }

    private Map<Integer, String[]> getClonedVMInfo(int vpdcSessionId,int vpdcId) {

        Map<Integer,String[]> cloneVMInfo               = new HashMap<Integer,String[]>();
        VpdcDetail vpdcDetail                         = null;
        List<VpdcDetail> vpdcDetails                  = null;

        if (0 == vpdcId && 0 != vpdcSessionId) {
            vpdcDetail = vpdcDetailDAO.findById(vpdcSessionId);
            vpdcDetails = vpdcDetailDAO.findVpdcDetailByVpdcIdAndOperation(vpdcDetail.getVpdc().getId(), OperationEnum.CloneVM);
        } else if (0 != vpdcId && 0 == vpdcSessionId) {
            vpdcDetails = vpdcDetailDAO.findVpdcDetailByVpdcIdAndOperation(vpdcId, OperationEnum.CloneVM);
        }

        if(!vpdcDetails.isEmpty()) {
            for (VpdcDetail detail : vpdcDetails) {
                YFilesConverter yFilesConverter = new YFilesConverter();
                yFilesConverter.loadGraphML(new ByteArrayInputStream(detail.getGuiXml().getBytes()));
                if (detail.getSpecXml() != null) {
                    for (String custHostName : getClonedVMFromSpecXML(detail.getSpecXml())) {
                        ServerDataObject serverDataObject = VCloudHelper.getInstance().getYComputeByComputeCustHostName(yFilesConverter.
                                getVPDCSpec(), custHostName);
                        cloneVMInfo.put(serverDataObject.getGuiId(),
                                new String[]{custHostName, serverDataObject.getNodeStatus()});
                    }
                }
            }
        }
        log.info("The return CloneVM info is : " + cloneVMInfo.toString());

        return cloneVMInfo;
    }

    private List<String> getClonedVMFromSpecXML(String specXML){

        XMLEventReader eventReader             = null;
        List<String> cloneVMInfo               = new ArrayList<String>();
        StringReader stringReader              = new StringReader(specXML);
        XMLInputFactory inputFactory           = XMLInputFactory.newInstance();
        String apiName = Thread.currentThread().getStackTrace()[1].getMethodName();

        try {
            boolean inTargetCompute = false;
            eventReader = inputFactory.createXMLEventReader(stringReader);
            while (eventReader.hasNext()) {
                XMLEvent event = eventReader.nextEvent();
                if (event.isStartElement()) {
                    StartElement startElement = event.asStartElement();
                    String localPart = startElement.getName().getLocalPart();
                    if ("targetCompute".equals(localPart)) {
                        inTargetCompute = true;
                    } else if (inTargetCompute && "custHostname".equals(localPart)) {
                        cloneVMInfo.add(eventReader.getElementText());
                        inTargetCompute = false;
                    }
                }
            }
        } catch (Exception e) {
            throw new SystemException(e.getMessage(), e);
        } finally {
            if (eventReader != null) {
                try {
                    eventReader.close();
                } catch (Exception e) {
                }
            }
        }
        return cloneVMInfo;

    }

    private void setGuiXML(VpdcDetail vpdcDetail, VpdcQueueProcess vpdcQueueProcess, FirewallRequest request) {
        log.info("create a new gui xml for getFirewall api");
        YFilesConverter yFilesConverter = new YFilesConverter();
        List<FWRule> pfwRules = null;
        List<SFWRule> stfwRules = null;
        List<VCloudFirewallRule> vCloudPfwRules = null;
        List<VCloudFirewallRule> vCloudStfwRules = null;
        if (MWUtil.isNotEmptyString(vpdcDetail.getGuiXml())) {
            yFilesConverter.loadGraphML(new ByteArrayInputStream(vpdcDetail.getGuiXml().getBytes()));
            VPDCSpec vpdcSpec = yFilesConverter.getVPDCSpec();
            PerimeterFWDataObject perimeterFWDataObject = vpdcSpec.getPerimeterFW();
            SFWDataObject sfwDataObject = vpdcSpec.getServerTierFW();
            if (null != vpdcSpec && null != vpdcSpec.getPerimeterFW().getFwRules() && vpdcSpec.getPerimeterFW().getFwRules().size() > 0) {
                pfwRules = perimeterFWDataObject.getFwRules();
            }
            if (null != vpdcSpec && null != vpdcSpec.getServerTierFW().getSFwRules() && vpdcSpec.getServerTierFW().getSFwRules().size() > 0) {
                stfwRules = sfwDataObject.getSFwRules();
            }
            vCloudPfwRules = request.getPfwRules().getPfwRules();
            vCloudStfwRules = request.getStwfRules().getStwfRules();
            if (null != vCloudPfwRules && vCloudStfwRules.size() > 0) {
                for (VCloudFirewallRule vCloudFirewallRule : vCloudPfwRules) {
                    FWRule fwRule = new FWRule();
                    fwRule.setAction(vCloudFirewallRule.getAction().toString());
                    fwRule.setDestination(vCloudFirewallRule.getDestination());
                    fwRule.setDestinationPort(vCloudFirewallRule.getDestinationPort());
                    fwRule.setLog(vCloudFirewallRule.getLog().toString());
                    fwRule.setNodeStatus(vCloudFirewallRule.getStatus());
                    fwRule.setProtocol(vCloudFirewallRule.getProtocol());
                    fwRule.setSource(vCloudFirewallRule.getSource());
                    pfwRules.add(fwRule);
                }
            }
            if (null != vCloudStfwRules && vCloudStfwRules.size() > 0) {
                for (VCloudFirewallRule vCloudFirewallRule : vCloudStfwRules) {
                    SFWRule fwRule = new SFWRule();
                    fwRule.setAction(vCloudFirewallRule.getAction().toString());
                    fwRule.setDestination(vCloudFirewallRule.getDestination());
                    fwRule.setDestinationPort(vCloudFirewallRule.getDestinationPort());
                    fwRule.setLog(vCloudFirewallRule.getLog().toString());
                    fwRule.setNodeStatus(vCloudFirewallRule.getStatus());
                    fwRule.setProtocol(vCloudFirewallRule.getProtocol());
                    fwRule.setSource(vCloudFirewallRule.getSource());
                    stfwRules.add(fwRule);
                }
            }

            perimeterFWDataObject.setFwRules(pfwRules);
            sfwDataObject.setSFwRules(stfwRules);
            yFilesConverter.updateCustomObject(perimeterFWDataObject);
            yFilesConverter.updateCustomObject(sfwDataObject);

            String newGuiXML = yFilesConverter.getGraphML();
            log.info("new gui xml generated++++++++" + newGuiXML);

            vpdcQueueProcess.setGuiXml(newGuiXML);

        }
    }

    private void putDetachVMDKRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        DetachVCloudVMDKRequest request = (DetachVCloudVMDKRequest) inputRequest;
        vpdcQueueProcess.setBillingSiteId(request.getSourceBillingSiteid());
        vpdcQueueProcess.setVpdcId(request.getSourceVpdcId());
        vpdcQueueProcess.setProcessName("DetachVCloudVMDK");
        vpdcQueueProcess.setProcessIdentifier("02");
        VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getSourceVpdcId());
        if (null != vpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(vpdcDetail.getVpdcName());
        }
        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(String.valueOf(vpdcQueueProcess.getProcessId()));
        taskInfo.setOrgId(request.getSourceBillingSiteid());
        taskInfo.setOwnerId(String.valueOf(request.getSourceVpdcId()));
        taskInfo.setProcessName("DetachVCloudVMDK");
        TaskResultInfo taskResultInfo = new TaskResultInfo();
        taskResultInfo.setResultReference(request.getLabelName());
        taskResultInfo.setResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
        vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
        vpdcQueueProcessResult.setProcessResultName(request.getLabelName());
        vpdcQueueProcessResult.setProcessResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        vpdcQueueProcessResult.setProcessResultId(request.getSourceVMDKciid());
        taskResultInfo.setResultReferenceId(String.valueOf(request.getSourceVMDKciid()));
        vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
        taskResultInfo.setResultId(String.valueOf(vpdcQueueProcessResult.getId()));
        taskResultInfoList.add(taskResultInfo);
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putAttachVMDKRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        AttachVCloudVMDKRequest request = (AttachVCloudVMDKRequest) inputRequest;
        vpdcQueueProcess.setBillingSiteId(request.getSourceBillingSiteid());
        vpdcQueueProcess.setVpdcId(request.getSourceVpdcId());
        vpdcQueueProcess.setProcessName("AttachVCloudVMDK");
        vpdcQueueProcess.setProcessIdentifier("02");
        VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getSourceVpdcId());
        if (null != vpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(vpdcDetail.getVpdcName());
        }
        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(String.valueOf(vpdcQueueProcess.getProcessId()));
        taskInfo.setOrgId(request.getSourceBillingSiteid());
        taskInfo.setOwnerId(String.valueOf(request.getSourceVpdcId()));
        taskInfo.setProcessName("AttachVCloudVMDK");
        TaskResultInfo taskResultInfo = new TaskResultInfo();
        taskResultInfo.setResultReference(request.getTargetMountPointName());
        taskResultInfo.setResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
        vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
        vpdcQueueProcessResult.setProcessResultName(request.getTargetMountPointName());
        vpdcQueueProcessResult.setProcessResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        vpdcQueueProcessResult.setProcessResultId(request.getSourceVMDKciid());
        taskResultInfo.setResultReferenceId(String.valueOf(request.getSourceVMDKciid()));
        vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
        taskResultInfo.setResultId(String.valueOf(vpdcQueueProcessResult.getId()));
        taskResultInfoList.add(taskResultInfo);
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putDeleteVMDKRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        String driveName = "";
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        DeleteVCloudVMDKRequest request = (DeleteVCloudVMDKRequest) inputRequest;
        vpdcQueueProcess.setBillingSiteId(request.getSourceBillingSiteid());
        vpdcQueueProcess.setVpdcId(request.getSourceVpdcId());
        vpdcQueueProcess.setProcessName("DeleteVCloudVMDK");
        vpdcQueueProcess.setProcessIdentifier("02");
        VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getSourceVpdcId());
        if (null != vpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(vpdcDetail.getVpdcName());
            String vpdcFinalXML = vpdcDetail.getDesignFinalXml().replaceAll("(\r\n|\r|\n|\n\r)", "");
            Drive drive = objectConverter.getDriveByVMDKCiIdFromFinal(request.getSourceVMDKciid(), vpdcFinalXML);
            driveName = drive.getMount();
        }
        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(String.valueOf(vpdcQueueProcess.getProcessId()));
        taskInfo.setOrgId(request.getSourceBillingSiteid());
        taskInfo.setOwnerId(String.valueOf(request.getSourceVpdcId()));
        taskInfo.setProcessName("DeleteVCloudVMDK");
        TaskResultInfo taskResultInfo = new TaskResultInfo();
        taskResultInfo.setResultReference(String.valueOf(request.getSourceVMDKciid()));
        taskResultInfo.setResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
        vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
        vpdcQueueProcessResult.setProcessResultName(driveName);
        vpdcQueueProcessResult.setProcessResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        vpdcQueueProcessResult.setProcessResultId(request.getSourceVMDKciid());
        taskResultInfo.setResultReferenceId(String.valueOf(request.getSourceVMDKciid()));
        vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
        taskResultInfo.setResultId(String.valueOf(vpdcQueueProcessResult.getId()));
        taskResultInfoList.add(taskResultInfo);
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

    private void putCloneVMDKRequestInQueue(Object inputRequest, VpdcQueueProcess vpdcQueueProcess, TaskInfo taskInfo) {
        List<TaskResultInfo> taskResultInfoList = new ArrayList<TaskResultInfo>();
        CloneVCloudVMDKRequest request = (CloneVCloudVMDKRequest) inputRequest;
        vpdcQueueProcess.setBillingSiteId(request.getSourceBillingSiteid());
        vpdcQueueProcess.setVpdcId(request.getSourceVpdcId());
        vpdcQueueProcess.setProcessName("CloneVCloudVMDK");
        vpdcQueueProcess.setProcessIdentifier("02");
        VpdcDetail vpdcDetail = vpdcDetailDAO.findVpdcDtlLatestByVpdcId(request.getSourceVpdcId());
        if (null != vpdcDetail) {
            vpdcQueueProcess.setProcessOwnerName(vpdcDetail.getVpdcName());
            taskInfo.setOwnerReference(vpdcDetail.getVpdcName());
        }
        vpdcQueueProcessDAO.save(vpdcQueueProcess);
        taskInfo.setProcessId(String.valueOf(vpdcQueueProcess.getProcessId()));
        taskInfo.setOrgId(request.getSourceBillingSiteid());
        taskInfo.setOwnerId(String.valueOf(request.getSourceVpdcId()));
        taskInfo.setProcessName("CloneVCloudVMDK");
        TaskResultInfo taskResultInfo = new TaskResultInfo();
        taskResultInfo.setResultReference(request.getLabelName());
        taskResultInfo.setResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        VpdcQueueProcessResult vpdcQueueProcessResult = new VpdcQueueProcessResult();
        vpdcQueueProcessResult.setVpdcQueueProcess(vpdcQueueProcess);
        vpdcQueueProcessResult.setProcessResultName(request.getLabelName());
        vpdcQueueProcessResult.setProcessResultStatus(VpdcQueueProcessStatusEnum.QUEUED.name());
        vpdcQueueProcessResultDAO.save(vpdcQueueProcessResult);
        taskResultInfo.setResultId(String.valueOf(vpdcQueueProcessResult.getId()));
        taskResultInfoList.add(taskResultInfo);
        taskInfo.getTaskResultInfo().addAll(taskResultInfoList);
    }

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics