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);
}
}
}
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);
}
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", "");
}
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);
}
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);
}
}
Aggregations