Skip to content

Commit

Permalink
PAYARA-2453 Deployment Group upon Creation should be able to select a…
Browse files Browse the repository at this point in the history
…vailable instance (payara#2350)

* PAYARA-2453 Deployment Group upon Creation should be able to select available instance.

* Fixed a typo
  • Loading branch information
MeroRai authored and arjantijms committed Feb 1, 2018
1 parent 080fae1 commit 042a725
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
33 changes: 33 additions & 0 deletions appserver/admingui/cluster/src/main/resources/dg/dgNew.jsf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@
<!define name="content">
<event>
<!beforeCreate
gf.listInstances(optionKeys={"standaloneonly"} optionValues={"true"}, instances="#{pageSession.instanceList}" );
setAttribute(key="zero" value="$int{0}");
setAttribute(key="instancesSize" value="#{pageSession.instanceList.size()}");

if( #{requestScope.instancesSize}=#{requestScope.zero} ){
setPageSessionAttribute(key="showInstancesSection", value="#{false}");
}

if( #{requestScope.instancesSize}>#{requestScope.zero} ){
setPageSessionAttribute(key="showInstancesSection", value="#{true}");
convertListToArray(list="#{pageSession.instanceList}" array="#{pageSession.allInstancesArray}");
gf.convertListToOptionArray(list="#{pageSession.instanceList}", optionArray="#{pageSession.allAvailableInstances}");
py.sortDeploymentGroupSelectedInstancesStatus(availableInstances="#{pageSession.instanceList}" enabled="#{pageSession.enabledInstancesList}" disabled="#{pageSession.disabledInstancesList}");
convertListToArray(list="#{pageSession.enabledInstancesList}" array="#{pageSession.enabledInstancesArr}");
}
/>
</event>
<sun:form id="propertyForm" autoComplete="off">
Expand All @@ -68,6 +83,14 @@
createMap(result="#{requestScope.ct}");
mapPut(map="#{requestScope.ct}" key="id" value="#{pageSession.name}" );
gf.createEntity( endpoint="#{sessionScope.REST_URL}/deployment-groups/deployment-group" attrs="#{requestScope.ct}")

gf.listInstances(optionKeys={"standaloneonly"} optionValues={"true"}, instances="#{pageSession.instanceList}" );
setAttribute(key="zero" value="$int{0}");
setAttribute(key="instancesSize" value="#{pageSession.instanceList.size()}");
if ( #{requestScope.instancesSize}>#{requestScope.zero} ){
py.addSelectedInstancesToDeploymentGroup(endpoint="#{sessionScope.REST_URL}/deployment-groups/add-instance-to-deployment-group" selected="#{pageSession.enabledInstancesArr}" instances="#{pageSession.allInstancesArray}" deploymentGroup="#{pageSession.name}");
}

gf.redirect(page="#{request.contextPath}/cluster/dg/dgs.jsf?alertType=${alertType}&alertSummary=${alertSummary}&alertDetail=${alertDetail}");
/>
</sun:button>
Expand All @@ -87,6 +110,16 @@
<sun:property id="NameTextProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18ncs.dg.dgName}" >
<sun:textField id="NameText" text="#{pageSession.name}" styleClass="required" columns="$int{55}" maxLength="#{sessionScope.fieldLengths['maxLength.dg.dgName']}" required="#{true}" />
</sun:property>

<sun:property id="avaliableInstances" visible="#{pageSession.showInstancesSection}" labelAlign="left" noWrap="#{true}" overlapLabel="#{true}">
<sun:addRemove id="deploymentGroupAddRemove"
selectAll="$boolean{true}"
items="#{pageSession.allAvailableInstances}"
selected="#{pageSession.enabledInstancesArr}"
availableItemsLabel="$resource{i18ncs.dg.AvailableInstances}"
selectedItemsLabel="$resource{i18ncs.dg.SelectedInstances}">
</sun:addRemove>
</sun:property>
</sun:propertySheetSection>
</sun:propertySheet>
<sun:hidden id="helpKey" value="$resource{help_cluster.clusterNew}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ dg.InstanceNewPageTitle=New Payara Server Instance
dgInstanceNew.PageTitleHelp=Create a new server instance and associate it with this deployment group
dg.AvailableDeploymentGroup=Available Deployment Groups
dg.SelectedDeploymentGroup=Selected Deployment Groups
dg.AvailableInstances=Available Instances
dg.SelectedInstances=Selected Instances
clusterNew.DG=Deployment Group
clusterNew.DGHelp=Choose a deployment group for the instance
clusters.PageTitle=Clusters (Deprecated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,66 @@ public static void updateDeploymentGroups(HandlerContext handlerCtx) {

}
}

/**
* Sort selected and disabled Instances
*
* @param handlerctx
*/
@Handler(id = "py.sortDeploymentGroupSelectedInstancesStatus",
input = {
@HandlerInput(name = "availableInstances", type = List.class, required = true)},
output = {
@HandlerOutput(name = "enabled", type = List.class),
@HandlerOutput(name = "disabled", type = List.class)})
public static void sortDeploymentGroupSelectedInstancesStatus(HandlerContext handlerctx) {
List<String> enabled = new ArrayList<>();
List<String> disabled = new ArrayList<>();
List<String> available = (List) handlerctx.getInputValue("availableInstances");

for (String unused : available) {
disabled.add(unused);
}
handlerctx.setOutputValue("disabled", disabled);
handlerctx.setOutputValue("enabled", enabled);

}

/**
* Add selected Instances to Deployment Groups
*
* @param handlerCtx
*/
@Handler(id = "py.addSelectedInstancesToDeploymentGroup",
input = {
@HandlerInput(name = "endpoint", type = String.class, required = true),
@HandlerInput(name = "selected", type = String[].class, required = true),
@HandlerInput(name = "instances", type = String[].class, required = true),
@HandlerInput(name = "deploymentGroup", type = String.class, required = true),
@HandlerInput(name = "quiet", type = boolean.class, defaultValue = "false"),
@HandlerInput(name = "throwException", type = boolean.class, defaultValue = "true"),})
public static void addSelectedInstancesToDeploymentGroup(HandlerContext handlerCtx) {
String[] instances = (String[]) handlerCtx.getInputValue("instances");
String[] selected = (String[]) handlerCtx.getInputValue("selected");
String deploymentGroup = (String) handlerCtx.getInputValue("deploymentGroup");
String endpoint = (String) handlerCtx.getInputValue("endpoint");
Boolean quiet = (Boolean) handlerCtx.getInputValue("quiet");
Boolean throwException = (Boolean) handlerCtx.getInputValue("throwException");
List<String> enabledDeploymentGroups = Arrays.asList(selected);

if (selected.length > 0) {
HashMap<String, Object> attributes = new HashMap<>();
attributes.put("deploymentGroup", deploymentGroup);

for (String selectedInstance : instances) {
if (enabledDeploymentGroups.contains(selectedInstance)) {
attributes.put("instance", selectedInstance);
RestUtil.restRequest(endpoint, attributes, "post", handlerCtx, quiet, throwException);
}
}

}
}

@Handler(id="py.sortHealthcheckEnabledNotifierStatus",
input={
Expand Down

0 comments on commit 042a725

Please sign in to comment.