use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class ListApplicationRefsCommand method getAccessChecks.
@Override
public Collection<? extends AccessCheck> getAccessChecks() {
final List<AccessCheck> accessChecks = new ArrayList<AccessCheck>();
appRefs = domain.getApplicationRefsInTarget(target);
for (ApplicationRef appRef : appRefs) {
accessChecks.add(new AccessCheck(AccessRequired.Util.resourceNameFromConfigBeanProxy(appRef), "read"));
}
return accessChecks;
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class ApplicationConfigListener method disableApplication.
private void disableApplication(String appName) {
Application app = applications.getApplication(appName);
ApplicationRef appRef = domain.getApplicationRefInServer(server.getName(), appName);
// by the current server instance, do not unload
if (app == null || appRef == null) {
return;
}
ApplicationInfo appInfo = appRegistry.get(appName);
if (appInfo == null || !appInfo.isLoaded()) {
return;
}
try {
ActionReport report = new HTMLActionReporter();
UndeployCommandParameters commandParams = new UndeployCommandParameters();
commandParams.name = appName;
commandParams.target = server.getName();
commandParams.origin = UndeployCommandParameters.Origin.unload;
commandParams.command = UndeployCommandParameters.Command.disable;
deployment.disable(commandParams, app, appInfo, report, logger);
if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
throw new Exception(report.getMessage());
}
} catch (Exception e) {
logger.log(Level.SEVERE, KernelLoggerInfo.loadingApplicationErrorDisable, e);
throw new RuntimeException(e);
}
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class ShowComponentStatusCommand method execute.
public void execute(AdminCommandContext context) {
ActionReport.MessagePart part;
if (report == null) {
// We could handle this more elegantly by requiring that report be passed as an argument.
throw new IllegalStateException("Internal Error: The report should have been initializes by the preAuthorization method");
} else {
part = report.getTopMessagePart();
}
// for each matched version
Iterator it = matchedVersions.iterator();
while (it.hasNext()) {
String appName = (String) it.next();
String status = "disabled";
if (!DeploymentUtils.isDomainTarget(target)) {
ApplicationRef ref = domain.getApplicationRefInTarget(appName, target);
if (ref == null) {
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 (domain.isAppEnabledInTarget(appName, target)) {
status = "enabled";
}
ActionReport.MessagePart childPart = part.addChild();
String message = localStrings.getLocalString("component.status", "Status of {0} is {1}.", appName, status);
childPart.setMessage(message);
childPart.addProperty(DeploymentProperties.STATE, status);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef in project Payara by payara.
the class DeleteVirtualServer method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
ActionReport report = context.getActionReport();
httpService = config.getHttpService();
networkConfig = config.getNetworkConfig();
if (!exists()) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_NOT_EXISTS), vsid));
report.setActionExitCode(ExitCode.FAILURE);
return;
}
// reference check
String referencedBy = getReferencingListener();
if (referencedBy != null && referencedBy.length() != 0) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_REFERENCED), vsid, referencedBy));
report.setActionExitCode(ExitCode.FAILURE);
return;
}
try {
// we need to determine which deployed applications reference this virtual-server
List<ApplicationRef> appRefs = new ArrayList<ApplicationRef>();
for (ApplicationRef appRef : server.getApplicationRef()) {
if (appRef.getVirtualServers() != null && appRef.getVirtualServers().contains(vsid)) {
appRefs.add(appRef);
}
}
// transfer into the array of arguments
ConfigBeanProxy[] proxies = new ConfigBeanProxy[appRefs.size() + 1];
proxies[0] = httpService;
for (int i = 0; i < appRefs.size(); i++) {
proxies[i + 1] = appRefs.get(i);
}
ConfigSupport.apply(new ConfigUpdate(vsid), proxies);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_FAIL), vsid));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of com.sun.enterprise.config.serverbeans.ApplicationRef 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());
}
}
}
Aggregations