Search in sources :

Example 1 with VersioningSyntaxException

use of org.glassfish.deployment.versioning.VersioningSyntaxException in project Payara by payara.

the class CreateApplicationRefCommand 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();
    // retrieve matched version(s) if exist
    List<String> matchedVersions = null;
    if (enabled) {
        try {
            // warn users that they can use version expressions
            VersioningUtils.checkIdentifier(name);
            matchedVersions = new ArrayList<String>(1);
            matchedVersions.add(name);
        } catch (VersioningWildcardException ex) {
            // a version expression is supplied with enabled == true
            report.setMessage(localStrings.getLocalString("wildcard.not.allowed", "WARNING : version expression are available only with --enabled=false"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } catch (VersioningSyntaxException ex) {
            report.setMessage(ex.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (!deployment.isRegistered(name)) {
            report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", name));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } else {
        // retrieve matched version(s) if exist
        try {
            matchedVersions = versioningService.getMatchedVersions(name, null);
        } catch (VersioningException e) {
            report.failure(logger, e.getMessage());
            return;
        }
        // this is an unversioned behavior and the given application is not registered
        if (matchedVersions.isEmpty()) {
            report.setMessage(localStrings.getLocalString("ref.not.referenced.target", "Application {0} is not referenced by target {1}", name, target));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    ActionReport.MessagePart part = report.getTopMessagePart();
    boolean isVersionExpression = VersioningUtils.isVersionExpression(name);
    // for each matched version
    Iterator it = matchedVersions.iterator();
    while (it.hasNext()) {
        String appName = (String) it.next();
        Application app = applications.getApplication(appName);
        ApplicationRef applicationRef = domain.getApplicationRefInTarget(appName, target);
        if (applicationRef != null) {
            // if a versioned name has been provided to the command
            if (isVersionExpression) {
                ActionReport.MessagePart childPart = part.addChild();
                childPart.setMessage(localStrings.getLocalString("appref.already.exists", "Application reference {0} already exists in target {1}.", appName, target));
            } else {
                // returns failure if an untagged name has been provided to the command
                report.setMessage(localStrings.getLocalString("appref.already.exists", "Application reference {0} already exists in target {1}.", name, target));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        } else {
            Transaction t = new Transaction();
            if (app.isLifecycleModule()) {
                handleLifecycleModule(context, t);
                return;
            }
            ReadableArchive archive;
            File file = null;
            DeployCommandParameters commandParams = null;
            Properties contextProps;
            Map<String, Properties> modulePropsMap = null;
            ApplicationConfigInfo savedAppConfig = null;
            try {
                commandParams = app.getDeployParameters(null);
                commandParams.origin = Origin.create_application_ref;
                commandParams.command = Command.create_application_ref;
                commandParams.target = target;
                commandParams.virtualservers = virtualservers;
                commandParams.enabled = enabled;
                if (lbenabled != null) {
                    commandParams.lbenabled = lbenabled;
                }
                commandParams.type = app.archiveType();
                contextProps = app.getDeployProperties();
                modulePropsMap = app.getModulePropertiesMap();
                savedAppConfig = new ApplicationConfigInfo(app);
                URI uri = new URI(app.getLocation());
                file = new File(uri);
                if (!file.exists()) {
                    report.setMessage(localStrings.getLocalString("fnf", "File not found", file.getAbsolutePath()));
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
                archive = archiveFactory.openArchive(file);
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Error opening deployable artifact : " + file.getAbsolutePath(), e);
                report.setMessage(localStrings.getLocalString("unknownarchiveformat", "Archive format not recognized"));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            try {
                final ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, commandParams, report).source(archive).build();
                Properties appProps = deploymentContext.getAppProps();
                appProps.putAll(contextProps);
                // relativize the location so it could be set properly in
                // domain.xml
                String location = DeploymentUtils.relativizeWithinDomainIfPossible(new URI(app.getLocation()));
                appProps.setProperty(ServerTags.LOCATION, location);
                // relativize the URI properties so they could store in the
                // domain.xml properly on the instances
                String appLocation = appProps.getProperty(Application.APP_LOCATION_PROP_NAME);
                appProps.setProperty(Application.APP_LOCATION_PROP_NAME, DeploymentUtils.relativizeWithinDomainIfPossible(new URI(appLocation)));
                String planLocation = appProps.getProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME);
                if (planLocation != null) {
                    appProps.setProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME, DeploymentUtils.relativizeWithinDomainIfPossible(new URI(planLocation)));
                }
                String altDDLocation = appProps.getProperty(Application.ALT_DD_LOCATION_PROP_NAME);
                if (altDDLocation != null) {
                    appProps.setProperty(Application.ALT_DD_LOCATION_PROP_NAME, DeploymentUtils.relativizeWithinDomainIfPossible(new URI(altDDLocation)));
                }
                String runtimeAltDDLocation = appProps.getProperty(Application.RUNTIME_ALT_DD_LOCATION_PROP_NAME);
                if (runtimeAltDDLocation != null) {
                    appProps.setProperty(Application.RUNTIME_ALT_DD_LOCATION_PROP_NAME, DeploymentUtils.relativizeWithinDomainIfPossible(new URI(runtimeAltDDLocation)));
                }
                savedAppConfig.store(appProps);
                if (modulePropsMap != null) {
                    deploymentContext.setModulePropsMap(modulePropsMap);
                }
                if (enabled) {
                    versioningService.handleDisable(appName, target, deploymentContext.getActionReport(), context.getSubject());
                }
                if (domain.isCurrentInstanceMatchingTarget(target, appName, server.getName(), null)) {
                    deployment.deploy(deployment.getSniffersFromApp(app), deploymentContext);
                } else {
                    // send the APPLICATION_PREPARED event for DAS
                    events.send(new Event<DeploymentContext>(Deployment.APPLICATION_PREPARED, deploymentContext), false);
                }
                final List<String> targets = new ArrayList<String>(Arrays.asList(commandParams.target.split(",")));
                List<String> deploymentTarget = new ArrayList<>();
                // If targets contains Deployment Group, check if the application is already deployed to instances in it.
                for (String target : targets) {
                    if (isDeploymentGroup(target)) {
                        List<Server> instances = domain.getDeploymentGroupNamed(target).getInstances();
                        for (Server instance : instances) {
                            List<Application> applications = domain.getApplicationsInTarget(instance.getName());
                            List<String> listOfApplications = new ArrayList<>();
                            for (Application application : applications) {
                                listOfApplications.add(application.getName());
                            }
                            if (!listOfApplications.contains(appName)) {
                                deploymentTarget.add(instance.getName());
                            }
                        }
                    }
                }
                if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
                    try {
                        deployment.registerAppInDomainXML(null, deploymentContext, t, true);
                    } catch (TransactionFailure e) {
                        logger.warning("failed to create application ref for " + appName);
                    }
                }
                // if the target is DAS, we do not need to do anything more
                if (!isVersionExpression && DeploymentUtils.isDASTarget(target)) {
                    return;
                }
                final ParameterMap paramMap = deployment.prepareInstanceDeployParamMap(deploymentContext);
                if (!deploymentTarget.isEmpty()) {
                    replicateCommand(deploymentTarget, context, paramMap);
                } else {
                    replicateCommand(targets, context, paramMap);
                }
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Error during creating application ref ", e);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            } finally {
                try {
                    archive.close();
                } catch (IOException e) {
                    logger.log(Level.INFO, "Error while closing deployable artifact : " + file.getAbsolutePath(), e);
                }
            }
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) VersioningWildcardException(org.glassfish.deployment.versioning.VersioningWildcardException) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URI(java.net.URI) Iterator(java.util.Iterator) VersioningException(org.glassfish.deployment.versioning.VersioningException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) ParameterMap(org.glassfish.api.admin.ParameterMap) IOException(java.io.IOException) VersioningException(org.glassfish.deployment.versioning.VersioningException) VersioningWildcardException(org.glassfish.deployment.versioning.VersioningWildcardException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) IOException(java.io.IOException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Transaction(org.jvnet.hk2.config.Transaction) ApplicationConfigInfo(org.glassfish.deployment.common.ApplicationConfigInfo) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Example 2 with VersioningSyntaxException

use of org.glassfish.deployment.versioning.VersioningSyntaxException 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());
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ParameterMapExtractor(org.glassfish.common.util.admin.ParameterMapExtractor) ParameterMap(org.glassfish.api.admin.ParameterMap) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

Example 3 with VersioningSyntaxException

use of org.glassfish.deployment.versioning.VersioningSyntaxException in project Payara by payara.

the class GetClientStubsCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    Collection<Artifacts.FullAndPartURIs> artifactInfo = DeploymentUtils.downloadableArtifacts(matchingApp).getArtifacts();
    try {
        VersioningUtils.checkIdentifier(appname);
    } catch (VersioningSyntaxException ex) {
        report.failure(logger, ex.getMessage());
        return;
    }
    if (artifactInfo.size() == 0) {
        report.setMessage(localStrings.getLocalString(getClass(), "get-client-stubs.noStubApp", "there are no files to retrieve for application {0}", new Object[] { appname }));
        return;
    }
    try {
        DeployCommand.retrieveArtifacts(context, matchingApp, localDir);
    } catch (Exception e) {
        report.setFailureCause(e);
        report.failure(logger, localStrings.getLocalString(getClass(), "get-client-stubs.errorPrepDownloadedFiles", "Error preparing for download"), e);
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

Example 4 with VersioningSyntaxException

use of org.glassfish.deployment.versioning.VersioningSyntaxException in project Payara by payara.

the class AppClientGroupFacadeGenerator method earDirUserURIText.

private String earDirUserURIText(final DeploymentContext dc) {
    final DeployCommandParameters deployParams = dc.getCommandParameters(DeployCommandParameters.class);
    final String appName = deployParams.name();
    try {
        return VersioningUtils.getUntaggedName(appName) + "Client/";
    } catch (VersioningSyntaxException ex) {
        Logger.getLogger(JavaWebStartInfo.APPCLIENT_SERVER_MAIN_LOGGER, JavaWebStartInfo.APPCLIENT_SERVER_LOGMESSAGE_RESOURCE).log(Level.SEVERE, null, ex);
    }
    return appName;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

Example 5 with VersioningSyntaxException

use of org.glassfish.deployment.versioning.VersioningSyntaxException in project Payara by payara.

the class StandaloneAppClientDeployerHelper method facadeNameOnly.

/**
 * Returns the name (no path, no type) of the facade JAR.  This is used
 * in both creating the full name and URI of the facade as well as for
 * the name of a subdirectory in the user's download directory.
 *
 * @param dc
 * @return
 */
private String facadeNameOnly(DeploymentContext dc) {
    DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
    final String appName = params.name();
    try {
        return VersioningUtils.getUntaggedName(appName) + "Client";
    } catch (VersioningSyntaxException ex) {
        logger.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return appName + "Client";
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

Aggregations

VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)8 ActionReport (org.glassfish.api.ActionReport)4 File (java.io.File)3 IOException (java.io.IOException)3 ParameterMap (org.glassfish.api.admin.ParameterMap)3 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Logger (java.util.logging.Logger)2 RestEndpoint (org.glassfish.api.admin.RestEndpoint)2 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)2 Transaction (org.jvnet.hk2.config.Transaction)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 Application (com.sun.enterprise.config.serverbeans.Application)1 Module (com.sun.enterprise.config.serverbeans.Module)1 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1