use of com.sun.enterprise.config.serverbeans.Application in project Payara by payara.
the class UpgradeTest method applicationUpgrade.
@Test
public void applicationUpgrade() {
Applications apps = getHabitat().getService(Applications.class);
assertTrue(apps != null);
for (Application app : apps.getApplications()) {
assertTrue(app.getEngine().isEmpty());
assertTrue(app.getModule().size() == 1);
for (Module module : app.getModule()) {
assertTrue(module.getName().equals(app.getName()));
assertTrue(!module.getEngines().isEmpty());
}
}
}
use of com.sun.enterprise.config.serverbeans.Application in project Payara by payara.
the class ListSubComponentsCommand method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
ActionReport.MessagePart part = report.getTopMessagePart();
String applicationName = modulename;
if (appname != null) {
applicationName = appname;
}
try {
VersioningUtils.checkIdentifier(applicationName);
} catch (VersioningSyntaxException ex) {
report.setMessage(ex.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (!deployment.isRegistered(applicationName)) {
report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", applicationName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Application application = applications.getApplication(applicationName);
if (application.isLifecycleModule()) {
if (!terse) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
return;
}
ApplicationInfo appInfo = appRegistry.get(applicationName);
if (appInfo == null) {
report.setMessage(localStrings.getLocalString("application.not.enabled", "Application {0} is not in an enabled state", applicationName));
return;
}
com.sun.enterprise.deployment.Application app = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
if (app == null) {
if (!terse) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
return;
}
Map<String, String> subComponents;
Map<String, String> subComponentsMap = new HashMap<String, String>();
if (appname == null) {
subComponents = getAppLevelComponents(app, type, subComponentsMap);
} else {
// strip the version suffix (delimited by colon), if present
int versionSuffix = modulename.indexOf(':');
String versionLessModuleName = versionSuffix > 0 ? modulename.substring(0, versionSuffix) : modulename;
BundleDescriptor bundleDesc = app.getModuleByUri(versionLessModuleName);
if (bundleDesc == null) {
report.setMessage(localStrings.getLocalString("listsubcomponents.invalidmodulename", "Invalid module name", appname, modulename));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
subComponents = getModuleLevelComponents(bundleDesc, type, subComponentsMap);
}
// the type param can only have values "ejbs" and "servlets"
if (type != null) {
if (!type.equals("servlets") && !type.equals("ejbs")) {
report.setMessage(localStrings.getLocalString("listsubcomponents.invalidtype", "The type option has invalid value {0}. It should have a value of servlets or ejbs.", type));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
List<String> subModuleInfos = new ArrayList<String>();
if (!app.isVirtual()) {
subModuleInfos = getSubModulesForEar(app, type);
}
int[] longestValue = new int[2];
for (Map.Entry<String, String> entry : subComponents.entrySet()) {
String key = entry.getKey();
if (key.length() > longestValue[0]) {
longestValue[0] = key.length();
}
String value = entry.getValue();
if (value.length() > longestValue[1]) {
longestValue[1] = value.length();
}
}
StringBuilder formattedLineBuf = new StringBuilder();
for (int j = 0; j < 2; j++) {
longestValue[j] += 2;
formattedLineBuf.append("%-").append(longestValue[j]).append("s");
}
String formattedLine = formattedLineBuf.toString();
if (!terse && subComponents.isEmpty()) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
int i = 0;
for (String key : subComponents.keySet()) {
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(String.format(formattedLine, new Object[] { key, subComponents.get(key) }));
if (appname == null && !app.isVirtual()) {
// support for JSR88 client
if (subModuleInfos.get(i) != null) {
childPart.addProperty("moduleInfo", subModuleInfos.get(i));
}
}
if (resources) {
Module module = application.getModule(key);
if (module != null) {
ActionReport subReport = report.addSubActionsReport();
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("_list-resources", subReport, context.getSubject());
final ParameterMap parameters = new ParameterMap();
parameters.add("appname", application.getName());
parameters.add("modulename", module.getName());
inv.parameters(parameters).execute();
ActionReport.MessagePart subPart = subReport.getTopMessagePart();
for (ActionReport.MessagePart cp : subPart.getChildren()) {
ActionReport.MessagePart resourcesChildPart = childPart.addChild();
resourcesChildPart.setMessage(" " + cp.getMessage());
}
}
}
i++;
}
// add the properties for GUI to display
Set<String> keys = subComponentsMap.keySet();
for (String key : keys) {
part.addProperty(key, subComponentsMap.get(key));
}
// now this is the normal output for the list-sub-components command
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.Application in project Payara by payara.
the class DeleteApplicationRefCommand method execute.
/**
* Entry point from the framework into the command execution
* @param context context for the command.
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
UndeployCommandParameters commandParams = new UndeployCommandParameters();
if (server.isDas()) {
commandParams.origin = Origin.unload;
} else {
// delete application ref on instance
// is essentially an undeploy
commandParams.origin = Origin.undeploy;
}
commandParams.command = Command.delete_application_ref;
// for each matched version
Iterator it = matchedVersions.iterator();
while (it.hasNext()) {
String appName = (String) it.next();
Application application = applications.getApplication(appName);
if (application == 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("application.notreg", "Application {0} not registered", appName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
return;
}
ApplicationRef applicationRef = domain.getApplicationRefInTarget(appName, target);
if (applicationRef == 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("appref.not.exists", "Target {1} does not have a reference to application {0}.", appName, target));
report.setActionExitCode(ActionReport.ExitCode.WARNING);
}
return;
}
if (application.isLifecycleModule()) {
try {
deployment.unregisterAppFromDomainXML(appName, target, true);
} catch (Exception e) {
report.failure(logger, e.getMessage());
}
return;
}
try {
ReadableArchive source = null;
ApplicationInfo appInfo = deployment.get(appName);
if (appInfo != null) {
source = appInfo.getSource();
} else {
File location = new File(new URI(application.getLocation()));
source = archiveFactory.openArchive(location);
}
commandParams.name = appName;
commandParams.cascade = cascade;
final ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, commandParams, report).source(source).build();
deploymentContext.getAppProps().putAll(application.getDeployProperties());
deploymentContext.setModulePropsMap(application.getModulePropertiesMap());
if (domain.isCurrentInstanceMatchingTarget(target, appName, server.getName(), null) && appInfo != null) {
// stop and unload application if it's the target and the
// the application is in enabled state
deployment.unload(appInfo, deploymentContext);
}
if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
try {
if (server.isInstance()) {
// if it's on instance, we should clean up
// the bits
deployment.undeploy(appName, deploymentContext);
deploymentContext.clean();
if (!Boolean.valueOf(application.getDirectoryDeployed()) && source.exists()) {
FileUtils.whack(new File(source.getURI()));
}
deployment.unregisterAppFromDomainXML(appName, target);
} else {
deployment.unregisterAppFromDomainXML(appName, target, true);
}
} catch (TransactionFailure e) {
logger.warning("failed to delete application ref for " + appName);
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error during deleteing application ref ", e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
}
}
}
use of com.sun.enterprise.config.serverbeans.Application in project Payara by payara.
the class InstanceDeployCommand method execute.
@Override
public void execute(AdminCommandContext ctxt) {
long operationStartTime = Calendar.getInstance().getTimeInMillis();
final ActionReport report = ctxt.getActionReport();
final Logger logger = ctxt.getLogger();
ReadableArchive archive = null;
this.origin = Origin.deploy_instance;
this.command = Command._deploy;
this.previousContextRoot = preservedcontextroot;
if (previousVirtualServers != null) {
String vs = previousVirtualServers.getProperty(target);
if (vs != null) {
this.virtualservers = vs;
}
}
if (previousEnabledAttributes != null) {
String enabledAttr = previousEnabledAttributes.getProperty(target);
if (enabledAttr != null) {
String enabledAttrForApp = previousEnabledAttributes.getProperty(DeploymentUtils.DOMAIN_TARGET_NAME);
this.enabled = Boolean.valueOf(enabledAttr) && Boolean.valueOf(enabledAttrForApp);
}
}
try {
if (!path.exists()) {
report.setMessage(localStrings.getLocalString("fnf", "File not found", path.getAbsolutePath()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (snifferManager.hasNoSniffers()) {
String msg = localStrings.getLocalString("nocontainer", "No container services registered, done...");
report.failure(logger, msg);
return;
}
archive = archiveFactory.openArchive(path, this);
ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive, type);
if (archiveHandler == null) {
report.failure(logger, localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", path.getName()));
return;
}
// wait until all applications are loaded as we may have dependency on these, or the previous app is still
// starting
startupProvider.get();
// clean up any left over repository files
if (!keepreposdir.booleanValue()) {
FileUtils.whack(new File(env.getApplicationRepositoryPath(), VersioningUtils.getRepositoryName(name)));
}
ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, this, report).source(archive).build();
// clean up any remaining generated files
deploymentContext.clean();
deploymentContext.getAppProps().putAll(appprops);
processGeneratedContent(generatedcontent, deploymentContext, logger);
Transaction t = null;
Application application = applications.getApplication(name);
if (application != null) {
// application element already been synchronized over
t = new Transaction();
} else {
t = deployment.prepareAppConfigChanges(deploymentContext);
}
ApplicationInfo appInfo;
appInfo = deployment.deploy(deploymentContext);
if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
try {
moveAltDDFilesToPermanentLocation(deploymentContext, logger);
// register application information in domain.xml
if (application != null) {
// application element already synchronized over
// just write application-ref
deployment.registerAppInDomainXML(appInfo, deploymentContext, t, true);
} else {
// write both application and application-ref
deployment.registerAppInDomainXML(appInfo, deploymentContext, t);
}
} catch (Exception e) {
// roll back the deployment and re-throw the exception
deployment.undeploy(name, deploymentContext);
deploymentContext.clean();
throw e;
}
}
} catch (Throwable e) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
report.setFailureCause(e);
} finally {
try {
if (archive != null) {
archive.close();
}
} catch (IOException e) {
logger.log(Level.INFO, localStrings.getLocalString("errClosingArtifact", "Error while closing deployable artifact : ", path.getAbsolutePath()), e);
}
if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
logger.info(localStrings.getLocalString("deploy.done", "Deployment of {0} done is {1} ms", name, (Calendar.getInstance().getTimeInMillis() - operationStartTime)));
} else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
String errorMessage = report.getMessage();
Throwable cause = report.getFailureCause();
if (cause != null) {
String causeMessage = cause.getMessage();
if (causeMessage != null && !causeMessage.equals(errorMessage)) {
errorMessage = errorMessage + " : " + cause.getMessage();
}
logger.log(Level.SEVERE, errorMessage, cause.getCause());
}
report.setMessage(localStrings.getLocalString("failToLoadOnInstance", "Failed to load the application on instance {0} : {1}", server.getName(), errorMessage));
// reset the failure cause so command framework will not try
// to print the same message again
report.setFailureCause(null);
}
}
}
use of com.sun.enterprise.config.serverbeans.Application in project Payara by payara.
the class InstanceLifecycleModuleCommand method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
try {
Application application = applications.getApplication(name);
Transaction t = new Transaction();
// create a dummy context to hold params and props
DeployCommandParameters commandParams = new DeployCommandParameters();
commandParams.name = name;
commandParams.target = target;
commandParams.enabled = enabled;
commandParams.virtualservers = virtualservers;
ExtendedDeploymentContext lifecycleContext = new DeploymentContextImpl(report, null, commandParams, null);
lifecycleContext.getAppProps().putAll(appprops);
if (application != null) {
// application element already been synchronized over
// just write application-ref
deployment.registerAppInDomainXML(null, lifecycleContext, t, true);
} else {
// write both
t = deployment.prepareAppConfigChanges(lifecycleContext);
deployment.registerAppInDomainXML(null, lifecycleContext, t);
}
} catch (Exception e) {
report.failure(logger, e.getMessage());
}
}
Aggregations