All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.ibizsys.model.engine.cloud.CloudHubPSSystemEngine Maven / Gradle / Ivy

The newest version!
package net.ibizsys.model.engine.cloud;

import java.io.File;

import org.springframework.util.StringUtils;

import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.IPSSystemService;
import net.ibizsys.model.PSModelServiceImpl;
import net.ibizsys.model.engine.PSModelEngineException;
import net.ibizsys.model.engine.cloud.service.client.ICloudOSSClient;
import net.ibizsys.model.engine.cloud.sysutil.ICloudClientPSSysUtilEngine;
import net.ibizsys.model.engine.cloud.util.ICloudConfigService;
import net.ibizsys.model.engine.cloud.util.domain.DeploySystem;
import net.ibizsys.model.engine.sysutil.IPSSysUtilEngine;
import net.ibizsys.model.engine.util.KeyValueUtils;
import net.ibizsys.model.engine.util.ZipUtils;
import net.ibizsys.model.res.IPSSysUtil;

public class CloudHubPSSystemEngine extends CloudPSSystemEngineBase implements ICloudHubPSSystemEngine{

	private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(CloudHubPSSystemEngine.class);
	
	private ICloudConfigService cloudConfigService = null;
	private ICloudClientPSSysUtilEngine cloudClientPSSysUtilEngine;
	private String cloudHubSystemId = null;
	
	
	@Override
	protected void onPrepareSetting() throws Exception {
		this.setCloudHubSystemId(this.getPSModelEngineHolder().getParam(CLOUDHUBSYSTEMID, null));
		super.onPrepareSetting();
	}
	
	@Override
	protected void prepareSetting() throws Exception {
		super.prepareSetting();
		
		if(this.getCloudConfigService(true) == null) {
			prepareCloudConfigService();
			this.getCloudConfigService(false);
		}
		
		if(StringUtils.hasLength(this.getCloudHubSystemId())) {
			DeploySystem deploySystem = this.getCloudConfigService(false).getDeploySystem(this.getCloudHubSystemId());
			if(deploySystem.getSettings() != null) {
				this.getPSModelEngineHolder().setParamsIf(null, deploySystem.getSettings());
			}
		}
	}
	
	@Override
	protected void onInit() throws Exception {
		
		
		super.onInit();
		
		java.util.List psSysUtils = this.getPSSystem().getAllPSSysUtils();
		if (psSysUtils != null) {
			for (IPSSysUtil iPSSysUtil : psSysUtils) {
				IPSSysUtilEngine iPSSysUtilEngine = this.getPSModelEngineHolder().getPSModelEngine(iPSSysUtil, IPSSysUtilEngine.class);
				if(iPSSysUtilEngine instanceof ICloudClientPSSysUtilEngine) {
					cloudClientPSSysUtilEngine = (ICloudClientPSSysUtilEngine)iPSSysUtilEngine;
					continue;
				}
			}
		}
	}
	
	@Override
	protected void onStart() throws Exception {
		super.onStart();
		
		this.getCloudClientPSSysUtilEngine().getPSSubSysServiceAPIEngine();
	}
	
	protected void setCloudConfigService(ICloudConfigService cloudConfigService){
		this.cloudConfigService = cloudConfigService;
	}
	
//	protected ICloudConfigService getCloudConfigService(){
//		try {
//			return this.getCloudConfigService(false);
//		}
//		catch (Exception ex) {
//			throw new PSModelEngineException(this, ex.getMessage(), ex);
//		}
//		
//	}

	
	protected ICloudConfigService getCloudConfigService(boolean tryMode) throws Exception{
		if(this.cloudConfigService != null || tryMode) {
			return this.cloudConfigService;
		}
		throw new Exception("Cloud配置服务对象无效");
	}
	
	protected void prepareCloudConfigService() throws Exception{
		ICloudConfigService configService = this.getPSModelEngineHolder().getPSModelEngineAddin(this, null, ICloudConfigService.class);
		this.setCloudConfigService(configService);
	}
	

	@Override
	public IPSSystemService getPSSystemService(String systemId)  {
		try {
			return this.onGetPSSystemService(systemId);
		}
		catch (Throwable ex) {
			throw new PSModelEngineException(this, String.format("获取系统[%1$s]服务对象发生异常,%2$s", systemId, ex.getMessage()), ex);
		}
		
	}

	protected IPSSystemService onGetPSSystemService(String systemId) throws Throwable {
		
		String systemModelDigest = this.getCloudClientPSSysUtilEngine().getCloudDevOpsClient().getSystemModelDigest(systemId);
		log.debug(String.format("请求系统模型摘要[%1$s]返回:%2$s", systemId, systemModelDigest));


		if (!StringUtils.hasLength(systemModelDigest)) {
			throw new Exception(String.format("未定义远程模型配置"));
		}

		String[] items = systemModelDigest.split("[|]");
		if (items.length < 2) {
			throw new Exception(String.format("远程模型配置不正确"));
		}

		String fileId = items[1];
		
		
		File file = File.createTempFile("model", ".zip");
		
		String fileName = this.getCloudClientPSSysUtilEngine().getCloudOSSClient().download(ICloudOSSClient.OSSCAT_DYNAMODEL, fileId, file);

		File dynaModelFolder = new File(String.format("%1$s%2$s%3$s", file.getParentFile().getCanonicalPath(), File.separator, KeyValueUtils.genGuidEx()));;
		ZipUtils.unzip(file, dynaModelFolder);
		
		PSModelServiceImpl psModelServiceImpl = new PSModelServiceImpl();
		psModelServiceImpl.setPSModelFolderPath(dynaModelFolder.getCanonicalPath(), false);
		
		return psModelServiceImpl;
	}
	
	@Override
	public DeploySystem getDeploySystem(String systemId)  {
		try {
			return this.onGetDeploySystem(systemId);
		}
		catch (Throwable ex) {
			throw new PSModelEngineException(this, String.format("获取部署系统[%1$s]发生异常,%2$s", systemId, ex.getMessage()), ex);
		}
		
	}

	protected DeploySystem onGetDeploySystem(String systemId) throws Throwable {
		return this.getCloudConfigService(false).getDeploySystem(systemId);		
	}
	
	
	@Override
	public ICloudClientPSSysUtilEngine getCloudClientPSSysUtilEngine() {
		try {
			return this.getCloudClientPSSysUtilEngine(false);
		} catch (Exception ex) {
			throw new PSModelEngineException(this, "Cloud客户端系统功能引擎无效");
		}
	}

	protected ICloudClientPSSysUtilEngine getCloudClientPSSysUtilEngine(boolean tryMode) throws Exception{
		if(this.cloudClientPSSysUtilEngine != null || tryMode) {
			return this.cloudClientPSSysUtilEngine;
		}
		throw new Exception("Cloud客户端系统功能引擎无效");
	}

	@Override
	public String getCloudHubSystemId() {
		return cloudHubSystemId;
	}

	protected void setCloudHubSystemId(String cloudHubSystemId) {
		this.cloudHubSystemId = cloudHubSystemId;
	}
	
	
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy