Search in sources :

Example 26 with Transaction

use of org.jvnet.hk2.config.Transaction in project Payara by payara.

the class TemplateRestResource method setParentAndTagName.

public void setParentAndTagName(Dom parent, String tagName) {
    if (parent == null) {
        // prevent https://glassfish.dev.java.net/issues/show_bug.cgi?id=14125
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    this.parent = parent;
    this.tagName = tagName;
    synchronized (parent) {
        entity = parent.nodeElement(tagName);
    }
    if (entity == null) {
        // In some cases, the tagName requested is not found in the DOM tree.  This is true,
        // for example, for the various ZeroConf elements (e.g., transaction-service).  If
        // the zero conf element is not in domain.xml, then it won't be in the Dom tree
        // returned by HK2.  If that's the case, we can use ConfigModularityUtils.getOwningObject()
        // to find the ConfigBean matching the path requested, which will add the node to
        // the Dom tree. Once that's done, we can return that node and proceed as normal
        String location = buildPath(parent) + "/" + tagName;
        if (location.startsWith("domain/configs")) {
            final ConfigModularityUtils cmu = locatorBridge.getRemoteLocator().<ConfigModularityUtils>getService(ConfigModularityUtils.class);
            ConfigBeanProxy cbp = cmu.getOwningObject(location);
            if (cbp == null) {
                cbp = cmu.getConfigBeanInstanceFor(cmu.getOwningClassForLocation(location));
            }
            if (cbp != null) {
                entity = Dom.unwrap(cbp);
                childModel = entity.model;
            }
        }
    // throw new WebApplicationException(new Exception("Trying to create an entity using generic create"),Response.Status.INTERNAL_SERVER_ERROR);
    } else {
        childModel = entity.model;
    }
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigModularityUtils(com.sun.enterprise.config.modularity.ConfigModularityUtils)

Example 27 with Transaction

use of org.jvnet.hk2.config.Transaction in project Payara by payara.

the class ApplicationLifecycle method registerAppInDomainXML.

// register application information in domain.xml
@Override
public void registerAppInDomainXML(final ApplicationInfo applicationInfo, final DeploymentContext context, Transaction t, boolean appRefOnly) throws TransactionFailure {
    final Properties appProps = context.getAppProps();
    final DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
    if (t != null) {
        try {
            if (!appRefOnly) {
                Application app_w = context.getTransientAppMetaData(ServerTags.APPLICATION, Application.class);
                // adding the application element
                setRestAppAttributes(app_w, appProps);
                Applications apps_w = t.enroll(applications);
                apps_w.getModules().add(app_w);
                if (applicationInfo != null) {
                    applicationInfo.save(app_w);
                }
            }
            List<String> targets = new ArrayList<String>();
            if (!DeploymentUtils.isDomainTarget(deployParams.target)) {
                targets.add(deployParams.target);
            } else {
                List<String> previousTargets = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class);
                if (previousTargets == null) {
                    previousTargets = domain.getAllReferencedTargetsForApplication(deployParams.name);
                }
                targets = previousTargets;
            }
            String origVS = deployParams.virtualservers;
            Boolean origEnabled = deployParams.enabled;
            Properties previousVirtualServers = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, Properties.class);
            Properties previousEnabledAttributes = context.getTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, Properties.class);
            for (String target : targets) {
                // first reset the virtualservers, enabled attribute
                deployParams.virtualservers = origVS;
                deployParams.enabled = origEnabled;
                // applicable
                if (DeploymentUtils.isDomainTarget(deployParams.target)) {
                    String vs = previousVirtualServers.getProperty(target);
                    if (vs != null) {
                        deployParams.virtualservers = vs;
                    }
                    String enabledAttr = previousEnabledAttributes.getProperty(target);
                    if (enabledAttr != null) {
                        deployParams.enabled = Boolean.valueOf(enabledAttr);
                    }
                }
                if (deployParams.enabled == null) {
                    deployParams.enabled = Boolean.TRUE;
                }
                Server servr = domain.getServerNamed(target);
                if (servr != null) {
                    ApplicationRef instanceApplicationRef = domain.getApplicationRefInTarget(deployParams.name, servr.getName());
                    if (instanceApplicationRef == null) {
                        // adding the application-ref element to the standalone
                        // server instance
                        ConfigBeanProxy servr_w = t.enroll(servr);
                        // adding the application-ref element to the standalone
                        // server instance
                        ApplicationRef appRef = servr_w.createChild(ApplicationRef.class);
                        setAppRefAttributes(appRef, deployParams);
                        ((Server) servr_w).getApplicationRef().add(appRef);
                    }
                }
                Cluster cluster = domain.getClusterNamed(target);
                if (cluster != null) {
                    // adding the application-ref element to the cluster
                    // and instances
                    ConfigBeanProxy cluster_w = t.enroll(cluster);
                    ApplicationRef appRef = cluster_w.createChild(ApplicationRef.class);
                    setAppRefAttributes(appRef, deployParams);
                    ((Cluster) cluster_w).getApplicationRef().add(appRef);
                    for (Server svr : cluster.getInstances()) {
                        ConfigBeanProxy svr_w = t.enroll(svr);
                        ApplicationRef appRef2 = svr_w.createChild(ApplicationRef.class);
                        setAppRefAttributes(appRef2, deployParams);
                        ((Server) svr_w).getApplicationRef().add(appRef2);
                    }
                }
                DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
                if (dg != null) {
                    ConfigBeanProxy dg_w = t.enroll(dg);
                    ApplicationRef appRef = dg_w.createChild(ApplicationRef.class);
                    setAppRefAttributes(appRef, deployParams);
                    ((DeploymentGroup) dg_w).getApplicationRef().add(appRef);
                    for (Server svr : dg.getInstances()) {
                        ApplicationRef instanceApplicationRef = domain.getApplicationRefInTarget(deployParams.name, svr.getName());
                        if (instanceApplicationRef == null) {
                            ConfigBeanProxy svr_w = t.enroll(svr);
                            ApplicationRef appRef2 = svr_w.createChild(ApplicationRef.class);
                            setAppRefAttributes(appRef2, deployParams);
                            ((Server) svr_w).getApplicationRef().add(appRef2);
                        }
                    }
                }
            }
        } catch (TransactionFailure e) {
            t.rollback();
            throw e;
        } catch (Exception e) {
            t.rollback();
            throw new TransactionFailure(e.getMessage(), e);
        }
        try {
            t.commit();
        } catch (RetryableException e) {
            System.out.println("Retryable...");
            // TODO : do something meaninful here
            t.rollback();
        } catch (TransactionFailure e) {
            t.rollback();
            throw e;
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) MultiException(org.glassfish.hk2.api.MultiException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) IOException(java.io.IOException) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) RetryableException(org.jvnet.hk2.config.RetryableException) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 28 with Transaction

use of org.jvnet.hk2.config.Transaction in project Payara by payara.

the class ApplicationLifecycle method registerTenantWithAppInDomainXML.

@Override
public void registerTenantWithAppInDomainXML(final String appName, final ExtendedDeploymentContext context) throws TransactionFailure {
    final Transaction t = new Transaction();
    try {
        final AppTenant appTenant_w = writeableTenantForApp(appName, t);
        appTenant_w.setContextRoot(context.getAppProps().getProperty(ServerTags.CONTEXT_ROOT));
        appTenant_w.setTenant(context.getTenant());
        t.commit();
    } catch (TransactionFailure ex) {
        t.rollback();
        throw ex;
    } catch (Throwable ex) {
        t.rollback();
        throw new TransactionFailure(ex.getLocalizedMessage(), ex);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transaction(org.jvnet.hk2.config.Transaction)

Example 29 with Transaction

use of org.jvnet.hk2.config.Transaction in project Payara by payara.

the class ApplicationLifecycle method unregisterTenantWithAppInDomainXML.

@Override
public void unregisterTenantWithAppInDomainXML(final String appName, final String tenantName) throws TransactionFailure, RetryableException {
    final com.sun.enterprise.config.serverbeans.Application app = applications.getApplication(appName);
    if (app == null) {
        throw new IllegalArgumentException("Application " + appName + " not found");
    }
    final AppTenants appTenants = app.getAppTenants();
    final AppTenant appTenant = appTenants.getAppTenant(tenantName);
    if (appTenant == null) {
        throw new IllegalArgumentException("Tenant " + tenantName + " not provisioned for application " + appName);
    }
    Transaction t = new Transaction();
    final AppTenants appTenants_w = t.enroll(appTenants);
    appTenants_w.getAppTenant().remove(appTenant);
    t.commit();
}
Also used : Transaction(org.jvnet.hk2.config.Transaction) com.sun.enterprise.config.serverbeans(com.sun.enterprise.config.serverbeans)

Example 30 with Transaction

use of org.jvnet.hk2.config.Transaction in project Payara by payara.

the class NodeAgentConfigUpgrade method postConstruct.

public void postConstruct() {
    final NodeAgents nodeAgents = domain.getNodeAgents();
    if (nodeAgents == null) {
        createDefaultNodeList();
        return;
    }
    final List<NodeAgent> agList = nodeAgents.getNodeAgent();
    if (agList.size() == 0) {
        createDefaultNodeList();
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Domain>() {

            public Object run(Domain d) throws PropertyVetoException, TransactionFailure {
                Nodes nodes = d.createChild(Nodes.class);
                Transaction t = Transaction.getTransaction(d);
                if (t == null)
                    return null;
                for (NodeAgent na : agList) {
                    String host = null;
                    Node node = nodes.createChild(Node.class);
                    node.setName(na.getName());
                    node.setType("CONFIG");
                    JmxConnector jc = na.getJmxConnector();
                    if (jc != null) {
                        // get the properties and see if host name is specified
                        List<Property> agentProp = jc.getProperty();
                        for (Property p : agentProp) {
                            String name = p.getName();
                            if (name.equals("client-hostname")) {
                                // create the node with a host name
                                node.setNodeHost(p.getValue());
                                node.setInstallDir("${com.sun.aas.productRoot}");
                            }
                        }
                    }
                    nodes.getNode().add(node);
                }
                // Now add the builtin localhost node
                createDefaultNode(d, nodes);
                d.setNodes(nodes);
                List<Server> serverList = servers.getServer();
                if (serverList.size() <= 0)
                    return null;
                for (Server s : serverList) {
                    s = t.enroll(s);
                    s.setNodeRef(s.getNodeAgentRef());
                    s.setNodeAgentRef(null);
                }
                // remove the node-agent element
                // d.getNodeAgents().getNodeAgent().clear();
                d.setNodeAgents(null);
                return null;
            }
        }, domain);
    } catch (Exception e) {
        Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading node-agent from V2 to V3", e);
        throw new RuntimeException(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Node(com.sun.enterprise.config.serverbeans.Node) NodeAgent(com.sun.enterprise.config.serverbeans.NodeAgent) JmxConnector(com.sun.enterprise.config.serverbeans.JmxConnector) NodeAgents(com.sun.enterprise.config.serverbeans.NodeAgents) Nodes(com.sun.enterprise.config.serverbeans.Nodes) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Domain(com.sun.enterprise.config.serverbeans.Domain) Property(org.jvnet.hk2.config.types.Property)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)14 Transaction (org.jvnet.hk2.config.Transaction)13 PropertyVetoException (java.beans.PropertyVetoException)10 Property (org.jvnet.hk2.config.types.Property)9 IOException (java.io.IOException)6 ActionReport (org.glassfish.api.ActionReport)6 File (java.io.File)5 Properties (java.util.Properties)5 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)5 Config (com.sun.enterprise.config.serverbeans.Config)4 Domain (com.sun.enterprise.config.serverbeans.Domain)4 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)4 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 Application (com.sun.enterprise.config.serverbeans.Application)2 Resource (com.sun.enterprise.config.serverbeans.Resource)2 Server (com.sun.enterprise.config.serverbeans.Server)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2