Search in sources :

Example 1 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class PayaraRestApiHandlers method createClusterInstances.

/**
 * Create Deployment Group with Instances
 * @param handlerCtx
 */
@Handler(id = "py.createDeploymentGroupInstances", input = { @HandlerInput(name = "deploymentGroupName", type = String.class, required = true), @HandlerInput(name = "instanceRow", type = List.class, required = true) })
public static void createClusterInstances(HandlerContext handlerCtx) {
    String deploymentGroupName = (String) handlerCtx.getInputValue("deploymentGroupName");
    List<Map> instanceRow = (List<Map>) handlerCtx.getInputValue("instanceRow");
    Map<String, Object> instanceAttributesMap = new HashMap<>();
    String endpointForCreateInstance = GuiUtil.getSessionValue("REST_URL") + "/create-instance";
    for (Map Instance : instanceRow) {
        instanceAttributesMap.put("name", Instance.get("name"));
        instanceAttributesMap.put("deploymentgroup", deploymentGroupName);
        instanceAttributesMap.put("node", Instance.get("node"));
        try {
            GuiUtil.getLogger().info(endpointForCreateInstance);
            GuiUtil.getLogger().info(instanceAttributesMap.toString());
            RestUtil.restRequest(endpointForCreateInstance, instanceAttributesMap, "post", null, false);
            // set  load balancing weight
            String instanceLoadBalancingWeight = (String) Instance.get("weight");
            if (!GuiUtil.isEmpty(instanceLoadBalancingWeight)) {
                String encodedInstanceName = URLEncoder.encode((String) Instance.get("name"), "UTF-8");
                String endpoint = GuiUtil.getSessionValue("REST_URL") + "/servers/server/" + encodedInstanceName;
                Map loadBalancingWeightAttribute = new HashMap();
                loadBalancingWeightAttribute.put("lbWeight", instanceLoadBalancingWeight);
                RestUtil.restRequest(endpoint, loadBalancingWeightAttribute, "post", null, false);
            }
        } catch (Exception ex) {
            GuiUtil.getLogger().severe(GuiUtil.getCommonMessage("LOG_CREATE_DEPLOYMENT_GROUP_INSTANCE", new Object[] { deploymentGroupName, endpointForCreateInstance, instanceAttributesMap }));
            GuiUtil.prepareException(handlerCtx, ex);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 2 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class UpdateCenterHandlers method getUcList.

@Handler(id = "getUcList", input = { @HandlerInput(name = "state", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getUcList(HandlerContext handlerCtx) {
    List result = new ArrayList();
    if (Boolean.TRUE.equals(GuiUtil.getSessionValue("_noNetwork"))) {
        handlerCtx.setOutputValue("result", result);
        return;
    }
    try {
        Image img = getUpdateCenterImage();
        if (img == null) {
            handlerCtx.setOutputValue("result", result);
            return;
        }
        String state = (String) handlerCtx.getInputValue("state");
        if (state.equals("update")) {
            handlerCtx.setOutputValue("result", getUpdateDisplayList(img, false));
            return;
        }
        List<Fmri> displayList = null;
        if (state.equals("installed"))
            displayList = getInstalledList(img);
        else if (state.equals("addOn"))
            displayList = getAddOnList(img);
        if (displayList != null) {
            for (Fmri fmri : displayList) {
                Map oneRow = new HashMap();
                try {
                    Manifest manifest = img.getManifest(fmri);
                    oneRow.put("selected", false);
                    oneRow.put("fmri", fmri);
                    oneRow.put("fmriStr", fmri.toString());
                    putInfo(oneRow, "pkgName", fmri.getName());
                    putInfo(oneRow, "version", getPkgVersion(fmri.getVersion()));
                    putInfo(oneRow, "newVersion", "");
                    putInfo(oneRow, "category", getCategory(manifest));
                    putInfo(oneRow, "pkgSize", getPkgSize(manifest));
                    oneRow.put("size", Integer.valueOf(manifest.getPackageSize()));
                    putInfo(oneRow, "auth", fmri.getAuthority());
                    String tooltip = manifest.getAttribute(PKG_SUMMARY);
                    if (GuiUtil.isEmpty(tooltip))
                        tooltip = manifest.getAttribute(DESC);
                    putInfo(oneRow, "tooltip", tooltip);
                    result.add(oneRow);
                } catch (Exception ex) {
                    GuiUtil.getLogger().info("getUcList(): " + ex.getLocalizedMessage());
                    if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception ex1) {
        GuiUtil.getLogger().info("getUcList(): " + ex1.getLocalizedMessage());
        if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
            ex1.printStackTrace();
        }
    }
    handlerCtx.setOutputValue("result", result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Image(com.sun.pkg.client.Image) Manifest(com.sun.pkg.client.Manifest) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Fmri(com.sun.pkg.client.Fmri) Handler(com.sun.jsftemplating.annotation.Handler)

Example 3 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class UpdateCenterHandlers method getProxyInfo.

@Handler(id = "getProxyInfo", output = { @HandlerOutput(name = "connection", type = String.class), @HandlerOutput(name = "host", type = String.class), @HandlerOutput(name = "port", type = String.class) })
public static void getProxyInfo(HandlerContext handlerCtx) {
    Proxy proxy = SystemInfo.getProxy();
    if (proxy != null) {
        InetSocketAddress address = (InetSocketAddress) proxy.address();
        if (address != null) {
            handlerCtx.setOutputValue("connection", "useProxy");
            handlerCtx.setOutputValue("host", address.getHostName());
            handlerCtx.setOutputValue("port", address.getPort());
            return;
        }
    }
    handlerCtx.setOutputValue("connection", "direct");
    handlerCtx.setOutputValue("host", "");
    handlerCtx.setOutputValue("port", "");
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) Handler(com.sun.jsftemplating.annotation.Handler)

Example 4 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class ApplicationHandlers method getLifecyclesInfo.

@Handler(id = "gf.getLifecyclesInfo", input = { @HandlerInput(name = "children", type = List.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getLifecyclesInfo(HandlerContext handlerCtx) {
    List<Map> children = (List) handlerCtx.getInputValue("children");
    List result = new ArrayList();
    String prefix = GuiUtil.getSessionValue("REST_URL") + "/applications/application/";
    if (children == null) {
        handlerCtx.setOutputValue("result", result);
        return;
    }
    for (Map oneChild : children) {
        Map oneRow = new HashMap();
        try {
            String name = (String) oneChild.get("message");
            String encodedName = URLEncoder.encode(name, "UTF-8");
            oneRow.put("name", name);
            oneRow.put("encodedName", encodedName);
            oneRow.put("selected", false);
            oneRow.put("loadOrder", RestUtil.getPropValue(prefix + encodedName, "load-order", handlerCtx));
            oneRow.put("enableURL", DeployUtil.getTargetEnableInfo(name, true, true));
            result.add(oneRow);
        } catch (Exception ex) {
            GuiUtil.getLogger().info(GuiUtil.getCommonMessage("log.error.getLifecyclesInfo") + ex.getLocalizedMessage());
            if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
                ex.printStackTrace();
            }
        }
    }
    handlerCtx.setOutputValue("result", result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 5 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class ApplicationHandlers method deleteLifecycle.

@Handler(id = "gf.deleteLifecycle", input = { @HandlerInput(name = "selectedList", type = List.class, required = true) })
public static void deleteLifecycle(HandlerContext handlerCtx) {
    List<Map> selectedList = (List) handlerCtx.getInputValue("selectedList");
    String endpoint = GuiUtil.getSessionValue("REST_URL") + "/applications/application/delete-lifecycle-module";
    Map attrs = new HashMap();
    try {
        for (Map oneRow : selectedList) {
            String name = (String) oneRow.get("name");
            String encodedName = URLEncoder.encode(name, "UTF-8");
            attrs.put("id", encodedName);
            // delete all application-ref first
            List<Map> appRefs = DeployUtil.getRefEndpoints(name, "application-ref");
            for (Map oneRef : appRefs) {
                attrs.put("target", oneRef.get("targetName"));
                RestUtil.restRequest((String) oneRef.get("endpoint"), attrs, "DELETE", null, false);
            }
            attrs.put("target", "domain");
            RestUtil.restRequest(endpoint, attrs, "POST", handlerCtx, false);
        }
    } catch (Exception ex) {
        GuiUtil.prepareException(handlerCtx, ex);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

Handler (com.sun.jsftemplating.annotation.Handler)175 Map (java.util.Map)97 ArrayList (java.util.ArrayList)94 HashMap (java.util.HashMap)93 List (java.util.List)88 TreeMap (java.util.TreeMap)15 IOException (java.io.IOException)12 Date (java.util.Date)9 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)8 LayoutViewHandler (com.sun.jsftemplating.layout.LayoutViewHandler)8 Image (com.sun.pkg.client.Image)8 ListIterator (java.util.ListIterator)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FacesContext (javax.faces.context.FacesContext)7 AttributeList (javax.management.AttributeList)7 RestResponse (org.glassfish.admingui.common.util.RestResponse)7 URL (java.net.URL)6 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)6 MultipleListDataProvider (com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider)5 TableRowGroup (com.sun.webui.jsf.component.TableRowGroup)5