Search in sources :

Example 6 with InstanceDescriptor

use of fish.payara.micro.data.InstanceDescriptor in project Payara by payara.

the class PayaraMicroRuntimeImpl method run.

/**
 * Runs a Callable object on specified members of the Payara Micro Cluster
 * Functionally equivalent to the run method on ClusterCommandRunner passing in
 * all cluster members obtained from getClusteredPayaras()
 * @param <T> The Type of the Callable
 * @param members The collection of members to run the callable on
 * @param callable The Callable object to run
 * @return
 */
@Override
public <T extends Serializable> Map<InstanceDescriptor, Future<T>> run(Collection<InstanceDescriptor> members, Callable<T> callable) {
    HashSet<String> memberUUIDs = new HashSet<>(members.size());
    for (InstanceDescriptor member : members) {
        memberUUIDs.add(member.getMemberUUID());
    }
    Map<String, Future<T>> runCallable = instanceService.runCallable(memberUUIDs, callable);
    Map<InstanceDescriptor, Future<T>> result = new HashMap<>(runCallable.size());
    for (String uuid : runCallable.keySet()) {
        InstanceDescriptor id = instanceService.getDescriptor(uuid);
        if (id != null) {
            result.put(id, runCallable.get(uuid));
        }
    }
    return result;
}
Also used : InstanceDescriptor(fish.payara.micro.data.InstanceDescriptor) HashMap(java.util.HashMap) Future(java.util.concurrent.Future) HashSet(java.util.HashSet)

Example 7 with InstanceDescriptor

use of fish.payara.micro.data.InstanceDescriptor in project Payara by payara.

the class PayaraMicroRuntimeImpl method run.

/**
 * Runs an asadmin command on specified  members of the Payara Micro Cluster
 * Functionally equivalent to the run method of the ClusterCommandRunner passing in
 * all cluster members obtained from getClusteredPayaras()
 * @param command The name of the asadmin command to run
 * @param args The parameters to the command
 * @return
 */
@Override
public Map<InstanceDescriptor, Future<? extends ClusterCommandResult>> run(Collection<InstanceDescriptor> members, String command, String... args) {
    HashSet<String> memberUUIDs = new HashSet<>(members.size());
    for (InstanceDescriptor member : members) {
        memberUUIDs.add(member.getMemberUUID());
    }
    Map<String, Future<ClusterCommandResult>> commandResult = instanceService.executeClusteredASAdmin(memberUUIDs, command, args);
    Map<InstanceDescriptor, Future<? extends ClusterCommandResult>> result = new HashMap<>(commandResult.size());
    for (String uuid : commandResult.keySet()) {
        InstanceDescriptor id = instanceService.getDescriptor(uuid);
        if (id != null) {
            result.put(id, commandResult.get(uuid));
        }
    }
    return result;
}
Also used : InstanceDescriptor(fish.payara.micro.data.InstanceDescriptor) ClusterCommandResult(fish.payara.micro.ClusterCommandResult) HashMap(java.util.HashMap) Future(java.util.concurrent.Future) HashSet(java.util.HashSet)

Example 8 with InstanceDescriptor

use of fish.payara.micro.data.InstanceDescriptor in project Payara by payara.

the class PayaraMicroRuntimeImpl method run.

/**
 * Runs a Callable object on all members of the Payara Micro Cluster
 * Functionally equivalent to the run method on ClusterCommandRunner passing in
 * all cluster members obtained from getClusteredPayaras()
 * @param <T> The Type of the Callable
 * @param callable The Callable object to run
 * @return
 */
@Override
public <T extends Serializable> Map<InstanceDescriptor, Future<T>> run(Callable<T> callable) {
    // NEEDS TO HANDLE THE CASE FOR LOCAL RUNNING IF NO CLUSTER ENABLED
    Map<String, Future<T>> runCallable = instanceService.runCallable(callable);
    Map<InstanceDescriptor, Future<T>> result = new HashMap<>(runCallable.size());
    for (String uuid : runCallable.keySet()) {
        InstanceDescriptor id = instanceService.getDescriptor(uuid);
        if (id != null) {
            result.put(id, runCallable.get(uuid));
        }
    }
    return result;
}
Also used : InstanceDescriptor(fish.payara.micro.data.InstanceDescriptor) HashMap(java.util.HashMap) Future(java.util.concurrent.Future)

Example 9 with InstanceDescriptor

use of fish.payara.micro.data.InstanceDescriptor in project Payara by payara.

the class PayaraMicroRuntimeImpl method run.

/**
 * Runs an asadmin command on all members of the Payara Micro Cluster
 * Functionally equivalent to the run method of the ClusterCommandRunner passing in
 * all cluster members obtained from getClusteredPayaras()
 * @param command The name of the asadmin command to run
 * @param args The parameters to the command
 * @return
 */
@Override
public Map<InstanceDescriptor, Future<? extends ClusterCommandResult>> run(String command, String... args) {
    // NEEDS TO HANDLE THE CASE FOR LOCAL RUNNING IF NO CLUSTER ENABLED
    Map<String, Future<ClusterCommandResult>> commandResult = instanceService.executeClusteredASAdmin(command, args);
    Map<InstanceDescriptor, Future<? extends ClusterCommandResult>> result = new HashMap<>(commandResult.size());
    for (String uuid : commandResult.keySet()) {
        InstanceDescriptor id = instanceService.getDescriptor(uuid);
        if (id != null) {
            result.put(id, commandResult.get(uuid));
        }
    }
    return result;
}
Also used : InstanceDescriptor(fish.payara.micro.data.InstanceDescriptor) ClusterCommandResult(fish.payara.micro.ClusterCommandResult) HashMap(java.util.HashMap) Future(java.util.concurrent.Future)

Example 10 with InstanceDescriptor

use of fish.payara.micro.data.InstanceDescriptor in project Payara by payara.

the class SendAsadminCommand method getTargetInstanceDescriptors.

/**
 * Gets the GUIDs of the instances in the cluster that match the targets specified by the --targets option
 * @param targets The targets to match
 * @return A map of the target instance GUIDs and their respective InstanceDescriptors
 */
private Map<String, InstanceDescriptor> getTargetInstanceDescriptors(String targets) {
    Map<String, InstanceDescriptor> targetInstanceDescriptors = new HashMap<>();
    // Get all of the clustered instances
    Set<InstanceDescriptor> instances = payaraMicro.getClusteredPayaras();
    // explicit targets have been defined
    if (targets != null) {
        // Split the targets into an array to separate them out
        String[] splitTargets = targets.split(",");
        for (InstanceDescriptor instance : instances) {
            for (String target : splitTargets) {
                // Split the group from the instance name if a group has been provided, otherwise just match instances
                if (target.contains(":")) {
                    String[] splitTarget = target.split(":");
                    // Make sure it's in the correct format
                    if (splitTarget.length == 2) {
                        String targetGroup = splitTarget[0];
                        String targetInstance = splitTarget[1];
                        // Get the target GUIDS, taking into account wildcards
                        if (targetGroup.equals("*")) {
                            if (targetInstance.equals(("*"))) {
                                // Match everything
                                if (instance.isMicroInstance()) {
                                    targetInstanceDescriptors.put(instance.getMemberUUID(), instance);
                                }
                            } else {
                                // Match on instance name only
                                if (instance.getInstanceName().equalsIgnoreCase(targetInstance) && instance.isMicroInstance()) {
                                    targetInstanceDescriptors.put(instance.getMemberUUID(), instance);
                                    break;
                                }
                            }
                        } else if (targetInstance.equals(("*"))) {
                            // Match on group name only
                            if (instance.getInstanceGroup().equalsIgnoreCase(targetGroup) && instance.isMicroInstance()) {
                                targetInstanceDescriptors.put(instance.getMemberUUID(), instance);
                                break;
                            }
                        } else {
                            // Match on group and instance name
                            if ((instance.getInstanceGroup().equalsIgnoreCase(targetGroup) && instance.getInstanceName().equalsIgnoreCase(targetInstance)) && instance.isMicroInstance()) {
                                targetInstanceDescriptors.put(instance.getMemberUUID(), instance);
                                break;
                            }
                        }
                    } else {
                        throw new IllegalArgumentException("Target contains more than one colon \":\", " + "this is not allowed");
                    }
                } else {
                    // Match everything
                    if (target.equals(("*"))) {
                        if (instance.isMicroInstance()) {
                            targetInstanceDescriptors.put(instance.getMemberUUID(), instance);
                        }
                    } else {
                        // Match on instance name
                        if (instance.getInstanceName().equalsIgnoreCase(target) && instance.isMicroInstance()) {
                            targetInstanceDescriptors.put(instance.getMemberUUID(), instance);
                            break;
                        }
                    }
                }
            }
        }
    } else if (explicitTargets.length == 0) {
        for (InstanceDescriptor instance : instances) {
            // Only send the command to Micro instances
            if (instance.isMicroInstance()) {
                targetInstanceDescriptors.put(instance.getMemberUUID(), instance);
            }
        }
    }
    return targetInstanceDescriptors;
}
Also used : InstanceDescriptor(fish.payara.micro.data.InstanceDescriptor) HashMap(java.util.HashMap)

Aggregations

InstanceDescriptor (fish.payara.micro.data.InstanceDescriptor)10 HashMap (java.util.HashMap)7 Future (java.util.concurrent.Future)5 ClusterCommandResult (fish.payara.micro.ClusterCommandResult)3 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 ActionReport (org.glassfish.api.ActionReport)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 ListRestEndpointsCommand (fish.payara.appserver.rest.endpoints.config.admin.ListRestEndpointsCommand)1 URL (java.net.URL)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1