use of org.glassfish.common.util.admin.ParameterMapExtractor in project Payara by payara.
the class DisableCommand method execute.
/**
* Entry point from the framework into the command execution
* @param context context for the command.
*/
public void execute(AdminCommandContext context) {
if (origin == Origin.unload && command == Command.disable) {
// we should only validate this for the disable command
deployment.validateSpecifiedTarget(target);
}
InterceptorNotifier notifier = new InterceptorNotifier(habitat, null);
final DeployCommandSupplementalInfo suppInfo = new DeployCommandSupplementalInfo();
suppInfo.setAccessChecks(accessChecks);
report.setResultType(DeployCommandSupplementalInfo.class, suppInfo);
if (env.isDas() && DeploymentUtils.isDomainTarget(target)) {
// for each distinct enabled version in all known targets
Iterator it = enabledVersionsInTargets.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
appName = (String) entry.getKey();
List<String> targets = new ArrayList<String>((Set<String>) entry.getValue());
// replicate command to all referenced targets
try {
ParameterMapExtractor extractor = new ParameterMapExtractor(this);
ParameterMap paramMap = extractor.extract(Collections.EMPTY_LIST);
paramMap.set("DEFAULT", appName);
notifier.ensureBeforeReported(ExtendedDeploymentContext.Phase.REPLICATION);
ClusterOperationUtil.replicateCommand("disable", FailurePolicy.Error, FailurePolicy.Warn, FailurePolicy.Ignore, targets, context, paramMap, habitat);
} catch (Exception e) {
report.failure(logger, e.getMessage());
return;
}
}
} else if (isVersionExpressionWithWildcard) {
try {
if (matchedVersions == Collections.EMPTY_LIST) {
// no version matched by the expression
// nothing to do : success
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return;
}
String enabledVersion = versioningService.getEnabledVersion(appName, target);
if (matchedVersions.contains(enabledVersion)) {
// the enabled version is matched by the expression
appName = enabledVersion;
} else {
// the enabled version is not matched by the expression
// nothing to do : success
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return;
}
} catch (VersioningException e) {
report.failure(logger, e.getMessage());
return;
}
}
if (target == null) {
target = deployment.getDefaultTarget(appName, origin, _classicstyle);
}
if (env.isDas() || !isundeploy) {
// on instance side for partial deployment case
if (!deployment.isRegistered(appName)) {
if (env.isDas()) {
// let's only do this check for DAS to be more
// tolerable of the partial deployment case
report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", appName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
return;
}
if (!DeploymentUtils.isDomainTarget(target)) {
ApplicationRef ref = domain.getApplicationRefInTarget(appName, target);
if (ref == null) {
if (env.isDas()) {
// let's only do this check for DAS to be more
// tolerable of the partial deployment case
report.setMessage(localStrings.getLocalString("ref.not.referenced.target", "Application {0} is not referenced by target {1}", appName, target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
return;
}
}
}
/*
* If the target is a cluster instance, the DAS will broadcast the command
* to all instances in the cluster so they can all update their configs.
*/
if (env.isDas()) {
try {
notifier.ensureBeforeReported(ExtendedDeploymentContext.Phase.REPLICATION);
DeploymentCommandUtils.replicateEnableDisableToContainingCluster("disable", domain, target, appName, habitat, context, this);
} catch (Exception e) {
report.failure(logger, e.getMessage());
return;
}
}
try {
Application app = applications.getApplication(appName);
this.name = appName;
// SHOULD CHECK THAT WE ARE THE CORRECT TARGET BEFORE DISABLING
String serverName = server.getName();
if (serverName.equals(target) || (server.getCluster() != null && server.getCluster().getName().equals(target))) {
// wait until all applications are loaded. Otherwise we get "Application not registered"
startupProvider.get();
ApplicationInfo appInfo = deployment.get(appName);
final DeploymentContext basicDC = deployment.disable(this, app, appInfo, report, logger);
suppInfo.setDeploymentContext((ExtendedDeploymentContext) basicDC);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error during disabling: ", e);
if (env.isDas() || !isundeploy) {
// we should let undeployment go through
// on instance side for partial deployment case
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
}
}
if (enabledVersionsToDisable == Collections.EMPTY_SET) {
enabledVersionsToDisable = new HashSet<String>();
enabledVersionsToDisable.add(appName);
}
// iterating all the distinct enabled versions in all targets
Iterator it = enabledVersionsToDisable.iterator();
while (it.hasNext()) {
appName = (String) it.next();
if (!isundeploy && !report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
try {
deployment.updateAppEnabledAttributeInDomainXML(appName, target, false);
} catch (TransactionFailure e) {
logger.warning("failed to set enable attribute for " + appName);
}
}
}
}
use of org.glassfish.common.util.admin.ParameterMapExtractor in project Payara by payara.
the class EnableCommand method execute.
/**
* Entry point from the framework into the command execution
* @param context context for the command.
*/
public void execute(AdminCommandContext context) {
deployment.validateSpecifiedTarget(target);
InterceptorNotifier notifier = new InterceptorNotifier(habitat, null);
DeployCommandSupplementalInfo suppInfo = new DeployCommandSupplementalInfo();
suppInfo.setDeploymentContext(notifier.dc());
suppInfo.setAccessChecks(accessChecks);
report.setResultType(DeployCommandSupplementalInfo.class, suppInfo);
if (!deployment.isRegistered(name())) {
report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", name()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (!DeploymentUtils.isDomainTarget(target)) {
ApplicationRef applicationRef = domain.getApplicationRefInTarget(name(), target);
if (applicationRef == null) {
report.setMessage(localStrings.getLocalString("ref.not.referenced.target", "Application {0} is not referenced by target {1}", name(), target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// return if the application is already in enabled state
if (domain.isAppEnabledInTarget(name(), target)) {
logger.fine("The application is already enabled");
return;
}
if (env.isDas()) {
// try to disable the enabled version, if exist
try {
versioningService.handleDisable(name(), target, report, context.getSubject());
} catch (VersioningSyntaxException e) {
report.failure(logger, e.getMessage());
return;
}
if (DeploymentUtils.isDomainTarget(target)) {
List<String> targets = domain.getAllReferencedTargetsForApplication(name());
// replicate command to all referenced targets
try {
ParameterMapExtractor extractor = new ParameterMapExtractor(this);
ParameterMap paramMap = extractor.extract(Collections.EMPTY_LIST);
paramMap.set("DEFAULT", name());
notifier.ensureBeforeReported(Phase.REPLICATION);
ClusterOperationUtil.replicateCommand("enable", FailurePolicy.Error, FailurePolicy.Warn, FailurePolicy.Ignore, targets, context, paramMap, habitat);
} catch (Exception e) {
report.failure(logger, e.getMessage());
return;
}
}
try {
notifier.ensureBeforeReported(Phase.REPLICATION);
DeploymentCommandUtils.replicateEnableDisableToContainingCluster("enable", domain, target, name(), habitat, context, this);
} catch (Exception e) {
report.failure(logger, e.getMessage());
return;
}
}
try {
Application app = applications.getApplication(name());
ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), name());
// application is enabled.
try {
deployment.updateAppEnabledAttributeInDomainXML(name(), target, true);
} catch (TransactionFailure e) {
logger.log(Level.WARNING, "failed to set enable attribute for " + name(), e);
}
DeploymentContext dc = deployment.enable(target, app, appRef, report, logger);
suppInfo.setDeploymentContext((ExtendedDeploymentContext) dc);
if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
// update the domain.xml
try {
deployment.updateAppEnabledAttributeInDomainXML(name(), target, false);
} catch (TransactionFailure e) {
logger.log(Level.WARNING, "failed to set enable attribute for " + name(), e);
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error during enabling: ", e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
}
}
use of org.glassfish.common.util.admin.ParameterMapExtractor in project Payara by payara.
the class ApplicationLifecycle method prepareInstanceDeployParamMap.
@Override
public ParameterMap prepareInstanceDeployParamMap(DeploymentContext dc) throws Exception {
final DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
final Collection<String> excludedParams = new ArrayList<String>();
excludedParams.add(DeploymentProperties.PATH);
excludedParams.add(DeploymentProperties.DEPLOYMENT_PLAN);
excludedParams.add(DeploymentProperties.ALT_DD);
excludedParams.add(DeploymentProperties.RUNTIME_ALT_DD);
// We'll force it to true ourselves.
excludedParams.add(DeploymentProperties.UPLOAD);
final ParameterMap paramMap;
final ParameterMapExtractor extractor = new ParameterMapExtractor(params);
paramMap = extractor.extract(excludedParams);
prepareGeneratedContent(dc, paramMap);
// set the path and plan params
// get the location properties from the application so the token
// will be resolved
Application application = applications.getApplication(params.name);
Properties appProperties = application.getDeployProperties();
String archiveLocation = appProperties.getProperty(Application.APP_LOCATION_PROP_NAME);
final File archiveFile = new File(new URI(archiveLocation));
paramMap.set("DEFAULT", archiveFile.getAbsolutePath());
String planLocation = appProperties.getProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME);
if (planLocation != null) {
final File actualPlan = new File(new URI(planLocation));
paramMap.set(DeployCommandParameters.ParameterNames.DEPLOYMENT_PLAN, actualPlan.getAbsolutePath());
}
String altDDLocation = appProperties.getProperty(Application.ALT_DD_LOCATION_PROP_NAME);
if (altDDLocation != null) {
final File altDD = new File(new URI(altDDLocation));
paramMap.set(DeployCommandParameters.ParameterNames.ALT_DD, altDD.getAbsolutePath());
}
String runtimeAltDDLocation = appProperties.getProperty(Application.RUNTIME_ALT_DD_LOCATION_PROP_NAME);
if (runtimeAltDDLocation != null) {
final File runtimeAltDD = new File(new URI(runtimeAltDDLocation));
paramMap.set(DeployCommandParameters.ParameterNames.RUNTIME_ALT_DD, runtimeAltDD.getAbsolutePath());
}
// always upload the archives to the instance side
// but not directories. Note that we prepare a zip file containing
// the generated directories and pass that as a single parameter so it
// will be uploaded even though a deployment directory is not.
paramMap.set(DeploymentProperties.UPLOAD, "true");
// redeployment
if (params.previousContextRoot != null) {
paramMap.set(DeploymentProperties.PRESERVED_CONTEXT_ROOT, params.previousContextRoot);
}
// pass the app props so we have the information to persist in the
// domain.xml
Properties appProps = dc.getAppProps();
appProps.remove(DeploymentProperties.APP_CONFIG);
paramMap.set(DeploymentProperties.APP_PROPS, extractor.propertiesValue(appProps, ':'));
Properties previousVirtualServers = dc.getTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, Properties.class);
if (previousVirtualServers != null) {
paramMap.set(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, extractor.propertiesValue(previousVirtualServers, ':'));
}
Properties previousEnabledAttributes = dc.getTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, Properties.class);
if (previousEnabledAttributes != null) {
paramMap.set(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, extractor.propertiesValue(previousEnabledAttributes, ':'));
}
return paramMap;
}
use of org.glassfish.common.util.admin.ParameterMapExtractor in project Payara by payara.
the class PostUnregisterInstanceCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
final String clusterName = context.getActionReport().getResultType(String.class);
if (clusterName != null) {
try {
ParameterMapExtractor pme = new ParameterMapExtractor(this);
final ParameterMap paramMap = pme.extract();
List<String> targets = new ArrayList<String>();
List<Server> instances = target.getInstances(clusterName);
for (Server s : instances) {
targets.add(s.getName());
}
ClusterOperationUtil.replicateCommand("_unregister-instance", FailurePolicy.Warn, FailurePolicy.Warn, FailurePolicy.Ignore, targets, context, paramMap, habitat);
} catch (Exception e) {
report.failure(logger, e.getMessage());
}
}
}
use of org.glassfish.common.util.admin.ParameterMapExtractor in project Payara by payara.
the class MigrateTimers method execute.
/**
* Executes the command
*
* @param context information
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
String error = validate();
if (error != null) {
report.setMessage(error);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
if (needRedirect) {
needRedirect = false;
ParameterMapExtractor mapExtractor = new ParameterMapExtractor(this);
ParameterMap params = mapExtractor.extract();
logger.info(localStrings.getString("migrate.timers.redirect", target, params.toCommaSeparatedString()));
ClusterOperationUtil.replicateCommand("migrate-timers", FailurePolicy.Error, FailurePolicy.Error, FailurePolicy.Error, Arrays.asList(new String[] { target }), context, params, habitat);
return;
}
int totalTimersMigrated = migrateTimers(fromServer);
report.setMessage(localStrings.getString("migrate.timers.count", totalTimersMigrated, fromServer, target));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (Exception e) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
Aggregations