Search in sources :

Example 11 with DeploymentGroup

use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.

the class EjbDeployer method getOwnerId.

private String getOwnerId(String target) {
    // If target is a cluster or deployment group replace it with the instance
    List<Server> instances = Collections.EMPTY_LIST;
    Cluster cluster = domain.getClusterNamed(target);
    if (cluster != null) {
        instances = cluster.getInstances();
    } else {
        DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
        if (dg != null) {
            instances = dg.getInstances();
        } else {
            return target;
        }
    }
    // Try a random instance in a cluster
    int useInstance = random.nextInt(instances.size());
    Server s0 = instances.get(useInstance);
    if (s0.isRunning()) {
        return s0.getName();
    } else {
        // Pick the first running instead
        for (Server s : instances) {
            if (s.isRunning()) {
                return s.getName();
            }
        }
    }
    // cluster
    return s0.getName();
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 12 with DeploymentGroup

use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.

the class MigrateTimers method validateDG.

private String validateDG() {
    List<DeploymentGroup> dgs = targetUtil.getDGForInstance(fromServer);
    if (dgs == null) {
        return localStrings.getString("migrate.timers.fromServerNotDG", fromServer);
    }
    // in the same cluster as fromServer
    if (target.equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
        List<Server> instances = dgs.get(0).getInstances();
        for (Server instance : instances) {
            if (instance.isRunning() && !instance.getName().equals(fromServer)) {
                target = instance.getName();
                needRedirect = true;
            }
        }
        // if destination is still DAS, that means no running server is available
        if (target.equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            return localStrings.getString("migrate.timers.noRunningInstanceToChoose", target);
        }
    } else {
        // verify fromServer and destinationServer are in the same dg, and
        boolean inSameDG = false;
        for (DeploymentGroup dg : dgs) {
            for (Server instance : dg.getInstances()) {
                if (instance.getName().equals(target)) {
                    inSameDG = true;
                    break;
                }
            }
        }
        if (!inSameDG) {
            return localStrings.getString("migrate.timers.destinationIsNotInDG", target);
        }
        // verify destinationServer is running
        if (!isServerRunning(target)) {
            return localStrings.getString("migrate.timers.destinationServerIsNotAlive", target);
        }
    }
    return null;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 13 with DeploymentGroup

use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.

the class DatabaseEJBTimerService method memberRemoved.

@Override
public void memberRemoved(MemberEvent event) {
    // work out whether we should be attempting to migrate timers
    String server = event.getServer();
    String group = event.getServerGroup();
    String thisServer = serverEnv.getInstanceName();
    // check whether the server is any of the same clusters or deployment groups
    // as the disappeared server and if so migrate timers
    boolean migrate = false;
    Cluster forServer = domain.getClusterForInstance(server);
    if (forServer != null) {
        for (Server instance : forServer.getInstances()) {
            if (instance.getName().equals(thisServer)) {
                // if I am in the same cluster
                migrate = true;
                break;
            }
        }
    }
    if (!migrate) {
        for (DeploymentGroup deploymentGroup : domain.getDeploymentGroupsForInstance(server)) {
            for (Server instance : deploymentGroup.getInstances()) {
                if (instance.getName().equals(thisServer)) {
                    // if I am in the same cluster
                    migrate = true;
                    break;
                }
            }
        }
    }
    if (migrate) {
        migrateTimers(event.getServer());
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) PayaraCluster(fish.payara.nucleus.cluster.PayaraCluster) Cluster(com.sun.enterprise.config.serverbeans.Cluster) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 14 with DeploymentGroup

use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.

the class UpdateApplicationRefCommand method execute.

/**
 * Execution method for updating the configuration of an ApplicationRef.
 * Will be replicated if the target is a cluster.
 *
 * @param context context for the command.
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    // Make a list of all ApplicationRefs that need to change
    List<ApplicationRef> applicationRefsToChange = new ArrayList<>();
    // Add the ApplicationRef which is being immediately targetted
    {
        ApplicationRef primaryApplicationRef = domain.getApplicationRefInTarget(name, target);
        if (primaryApplicationRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("appref.not.exists", "Target {1} does not have a reference to application {0}.", name, target));
            return;
        }
        applicationRefsToChange.add(primaryApplicationRef);
    }
    // Add the implicitly targetted ApplicationRefs if the target is in a cluster or deployment group
    {
        Cluster cluster = domain.getClusterNamed(target);
        // if the target is a cluster
        if (cluster != null) {
            for (Server server : cluster.getInstances()) {
                ApplicationRef instanceAppRef = server.getApplicationRef(name);
                // if the server in the cluster contains the ApplicationRef
                if (instanceAppRef != null) {
                    applicationRefsToChange.add(instanceAppRef);
                }
            }
        }
        DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
        if (dg != null) {
            for (Server server : dg.getInstances()) {
                ApplicationRef instanceAppRef = server.getApplicationRef(name);
                // if the server in the dg contains the ApplicationRef
                if (instanceAppRef != null) {
                    applicationRefsToChange.add(instanceAppRef);
                }
            }
        }
    }
    // Apply the configuration to the listed ApplicationRefs
    try {
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
                for (ConfigBeanProxy proxy : params) {
                    if (proxy instanceof ApplicationRef) {
                        ApplicationRef applicationRefProxy = (ApplicationRef) proxy;
                        if (enabled != null) {
                            applicationRefProxy.setEnabled(enabled.toString());
                        }
                        if (virtualservers != null) {
                            applicationRefProxy.setVirtualServers(virtualservers);
                        }
                        if (lbenabled != null) {
                            applicationRefProxy.setLbEnabled(lbenabled.toString());
                        }
                    }
                }
                report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return true;
            }
        }, applicationRefsToChange.toArray(new ApplicationRef[] {}));
    } catch (TransactionFailure ex) {
        report.failure(logger, ex.getLocalizedMessage());
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) ArrayList(java.util.ArrayList) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) PropertyVetoException(java.beans.PropertyVetoException) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 15 with DeploymentGroup

use of fish.payara.enterprise.config.serverbeans.DeploymentGroup in project Payara by payara.

the class CreateJMSResource method filterForTarget.

private boolean filterForTarget(String jndiName) {
    // List<String> resourceList = new ArrayList();
    if (target != null) {
        List<ResourceRef> resourceRefs = null;
        Cluster cluster = domain.getClusterNamed(target);
        if (cluster != null)
            resourceRefs = cluster.getResourceRef();
        else {
            Server server = domain.getServerNamed(target);
            if (server != null) {
                resourceRefs = server.getResourceRef();
            } else {
                DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
                if (dg != null) {
                    resourceRefs = dg.getResourceRef();
                }
            }
        }
        if (resourceRefs != null && resourceRefs.size() != 0) {
            for (ResourceRef resource : resourceRefs) if (jndiName.equalsIgnoreCase(resource.getRef()))
                return true;
        }
    }
    return false;
}
Also used : DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Aggregations

DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)25 ActionReport (org.glassfish.api.ActionReport)10 Server (com.sun.enterprise.config.serverbeans.Server)9 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)7 ArrayList (java.util.ArrayList)6 Cluster (com.sun.enterprise.config.serverbeans.Cluster)5 Domain (com.sun.enterprise.config.serverbeans.Domain)5 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)5 Test (org.junit.Test)5 DeploymentGroups (fish.payara.enterprise.config.serverbeans.DeploymentGroups)4 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)3 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)3 PropertyVetoException (java.beans.PropertyVetoException)3 Logger (java.util.logging.Logger)3 ParameterMap (org.glassfish.api.admin.ParameterMap)3 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)3 DGServerRef (fish.payara.enterprise.config.serverbeans.DGServerRef)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)2