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();
}
}
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;
}
}
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;
}
Aggregations