Search in sources :

Example 6 with TIS

use of com.qlangtech.tis.TIS in project tis by qlangtech.

the class PluginAction method doInstallPlugins.

/**
 * 安装插件
 *
 * @param context
 */
public void doInstallPlugins(Context context) {
    JSONArray pluginsInstall = this.parseJsonArrayPost();
    if (pluginsInstall.size() < 1) {
        this.addErrorMessage(context, "请选择需要安装的插件");
        return;
    }
    long start = System.currentTimeMillis();
    boolean dynamicLoad = true;
    UUID correlationId = UUID.randomUUID();
    UpdateCenter updateCenter = TIS.get().getUpdateCenter();
    List<Future<UpdateCenter.UpdateCenterJob>> installJobs = new ArrayList<>();
    JSONObject willInstall = null;
    String pluginName = null;
    UpdateSite.Plugin plugin = null;
    List<PluginWrapper> batch = new ArrayList<>();
    for (int i = 0; i < pluginsInstall.size(); i++) {
        willInstall = pluginsInstall.getJSONObject(i);
        pluginName = willInstall.getString("name");
        if (StringUtils.isEmpty(pluginName)) {
            throw new IllegalStateException("plugin name can not empty");
        }
        plugin = updateCenter.getPlugin(pluginName);
        Future<UpdateCenter.UpdateCenterJob> installJob = plugin.deploy(dynamicLoad, correlationId, batch);
        installJobs.add(installJob);
    }
    if (dynamicLoad) {
        installJobs.add(updateCenter.addJob(updateCenter.new CompleteBatchJob(batch, start, correlationId)));
    }
    final TIS tis = TIS.get();
    // TODO: 每个安装流程都要进来
    if (true || !tis.getInstallState().isSetupComplete()) {
        tis.setInstallState(InstallState.INITIAL_PLUGINS_INSTALLING);
        updateCenter.persistInstallStatus();
        new Thread() {

            @Override
            public void run() {
                boolean failures = false;
                INSTALLING: while (true) {
                    try {
                        updateCenter.persistInstallStatus();
                        Thread.sleep(500);
                        failures = false;
                        for (Future<UpdateCenter.UpdateCenterJob> jobFuture : installJobs) {
                            if (!jobFuture.isDone() && !jobFuture.isCancelled()) {
                                continue INSTALLING;
                            }
                            UpdateCenter.UpdateCenterJob job = jobFuture.get();
                            if (job instanceof UpdateCenter.InstallationJob && ((UpdateCenter.InstallationJob) job).status instanceof UpdateCenter.DownloadJob.Failure) {
                                failures = true;
                            }
                        }
                    } catch (Exception e) {
                        logger.warn("Unexpected error while waiting for initial plugin set to install.", e);
                    }
                    break;
                }
                updateCenter.persistInstallStatus();
                if (!failures) {
                    InstallUtil.proceedToNextStateFrom(InstallState.INITIAL_PLUGINS_INSTALLING);
                    // 为了让Assemble等节点的uberClassLoader重新加载一次,需要主动向Assemble等节点发送一个指令
                    notifyPluginUpdate2AssembleNode(TIS.KEY_ACTION_CLEAN_TIS + "=true", "TIS");
                }
            }
        }.start();
    }
}
Also used : UpdateCenter(com.qlangtech.tis.extension.model.UpdateCenter) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) Future(java.util.concurrent.Future) UpdateSite(com.qlangtech.tis.extension.model.UpdateSite) TIS(com.qlangtech.tis.TIS)

Example 7 with TIS

use of com.qlangtech.tis.TIS in project tis by qlangtech.

the class InstallUtil method getDefaultInstallState.

private static InstallState getDefaultInstallState() {
    // Support a simple state override. Useful for testing.
    String stateOverride = System.getProperty("jenkins.install.state", System.getenv("jenkins.install.state"));
    if (stateOverride != null) {
        try {
            return InstallState.valueOf(stateOverride.toUpperCase());
        } catch (RuntimeException e) {
            throw new IllegalStateException("Unknown install state override specified on the commandline: '" + stateOverride + "'.");
        }
    }
    // Support a 3-state flag for running or disabling the setup wizard
    // String shouldRunFlag = SystemProperties.getString("jenkins.install.runSetupWizard");
    // boolean shouldRun = "true".equalsIgnoreCase(shouldRunFlag);
    // boolean shouldNotRun = "false".equalsIgnoreCase(shouldRunFlag);
    // install wizard will always run if environment specified
    // if (!shouldRun) {
    // if (Functions.getIsUnitTest()) {
    // return InstallState.TEST;
    // }
    // 
    // if (SystemProperties.getBoolean("hudson.Main.development")) {
    // return InstallState.DEVELOPMENT;
    // }
    // }
    // new VersionNumber(getLastExecVersion());
    VersionNumber lastRunVersion = null;
    // // has the setup wizard been completed?
    // if (!SetupWizard.getUpdateStateFile().exists()) {
    TIS j = TIS.get();
    // 
    // // Allow for skipping
    // if (shouldNotRun) {
    // try {
    // InstallState.INITIAL_SETUP_COMPLETED.initializeState();
    // return j.getInstallState();
    // } catch (RuntimeException e) {
    // throw e;
    // } catch (Exception e) {
    // throw new RuntimeException(e);
    // }
    // }
    // 
    // return InstallState.INITIAL_SECURITY_SETUP;
    // }
    // We have a last version.
    VersionNumber currentRunVersion = new VersionNumber(getCurrentExecVersion());
    if (lastRunVersion.isOlderThan(currentRunVersion)) {
        return InstallState.UPGRADE;
    } else if (lastRunVersion.isNewerThan(currentRunVersion)) {
        return InstallState.DOWNGRADE;
    } else {
        // Last running version was the same as "this" running version.
        return InstallState.RESTART;
    }
}
Also used : VersionNumber(com.qlangtech.tis.extension.util.VersionNumber) TIS(com.qlangtech.tis.TIS)

Example 8 with TIS

use of com.qlangtech.tis.TIS in project tis by qlangtech.

the class XStream2 method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
    TIS h = TIS.get();
    if (h != null && h.pluginManager != null && h.pluginManager.uberClassLoader != null) {
        setClassLoader(h.pluginManager.uberClassLoader);
    }
    Object o = super.unmarshal(reader, root, dataHolder);
    return o;
}
Also used : TIS(com.qlangtech.tis.TIS)

Aggregations

TIS (com.qlangtech.tis.TIS)8 JSONArray (com.alibaba.fastjson.JSONArray)2 JSONObject (com.alibaba.fastjson.JSONObject)2 Lists (com.google.common.collect.Lists)2 Config (com.qlangtech.tis.manage.common.Config)2 IncrStreamFactory (com.qlangtech.tis.plugin.incr.IncrStreamFactory)2 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 FileUtils (org.apache.commons.io.FileUtils)2 Context (com.alibaba.citrus.turbine.Context)1 KoubeiIbatorRunner (com.koubei.abator.KoubeiIbatorRunner)1 KoubeiProgressCallback (com.koubei.abator.KoubeiProgressCallback)1 RocketMQListenerFactory (com.qlangtech.async.message.client.consumer.RocketMQListenerFactory)1 MQListenerFactory (com.qlangtech.tis.async.message.client.consumer.impl.MQListenerFactory)1 IOutputEntry (com.qlangtech.tis.compiler.java.IOutputEntry)1 JavaCompilerProcess (com.qlangtech.tis.compiler.java.JavaCompilerProcess)1 IbatorProperties (com.qlangtech.tis.coredefine.module.action.IbatorProperties)1 IndexIncrStatus (com.qlangtech.tis.coredefine.module.action.IndexIncrStatus)1 Describable (com.qlangtech.tis.extension.Describable)1