Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Infrastructure params and Policy params rows in NS description #792

Open
wants to merge 3 commits into
base: NSDescriptionUpdate
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package org.ow2.proactive_grid_cloud_portal.rm.client;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

Expand Down Expand Up @@ -139,11 +140,13 @@ Canvas build() {
this.nsDetails.setCanSelectText(true);
DetailViewerField n1 = new DetailViewerField("sourceName", "Node Source");
DetailViewerField n2 = new DetailViewerField("infrastructure", "Infrastructure");
DetailViewerField n3 = new DetailViewerField("policy", "Policy");
DetailViewerField n4 = new DetailViewerField("nodeProvider", "Owner");
DetailViewerField n5 = new DetailViewerField("hosts", "Hosts");
DetailViewerField n6 = new DetailViewerField("nodes", "Nodes");
this.nsDetails.setFields(n1, n2, n3, n4, n5, n6);
DetailViewerField n3 = new DetailViewerField("infrastructureParameters", "Infrastructure Params");
DetailViewerField n4 = new DetailViewerField("policy", "Policy");
DetailViewerField n5 = new DetailViewerField("policyParameters", "Policy Params");
DetailViewerField n6 = new DetailViewerField("nodeProvider", "Owner");
DetailViewerField n7 = new DetailViewerField("hosts", "Hosts");
DetailViewerField n8 = new DetailViewerField("nodes", "Nodes");
this.nsDetails.setFields(n1, n2, n3, n4, n5, n6, n7, n8);
// Define node source canvas and append sections
this.nsCanvas = new VLayout();
this.nsCanvas.setWidth100();
Expand Down Expand Up @@ -375,10 +378,13 @@ public void nodeSourceSelected(NodeSource ns) {
numNodes += h.getNodes().size();
}

// Infrastructure and policy description
String infrastructure = "NO INFRASTRUCTURE DESCRIPTION";
String policy = "NO POLICY DESCRIPTION";
String infrastructure = null;
String infrastructureParams = null;
String policy = null;
String policyParams = null;

String[] NSPolicyAndInfra = ns.getSourceDescription().split("Infrastructure: |, Policy: ");

if (NSPolicyAndInfra.length == 3) {
infrastructure = NSPolicyAndInfra[1].trim();
policy = NSPolicyAndInfra[2].trim();
Expand All @@ -388,8 +394,22 @@ public void nodeSourceSelected(NodeSource ns) {
policy = NSPolicyAndInfra[0].trim();
}

if (infrastructure != null) {
String[] result = splitAndExtractNameAndParamsFromDescription(infrastructure);
infrastructure = result[0];
infrastructureParams = result[1];
}

if (policy != null) {
String[] result = splitAndExtractNameAndParamsFromDescription(policy);
policy = result[0];
policyParams = result[1];
}

dv.setAttribute("infrastructure", infrastructure);
dv.setAttribute("infrastructureParameters", infrastructureParams);
dv.setAttribute("policy", policy);
dv.setAttribute("policyParameters", policyParams);
dv.setAttribute("sourceName", ns.getSourceName());
dv.setAttribute("nodeProvider", ns.getNodeSourceAdmin());
dv.setAttribute("nodes", numNodes);
Expand Down Expand Up @@ -451,4 +471,11 @@ public void hostSelected(Host h) {
this.selNS = null;
this.selNode = null;
}

private String[] splitAndExtractNameAndParamsFromDescription(String input) {
String[] elements = input.split(",");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ideal, this suppose you have a comma after the infrastructure or policy name.
you should extract the first word of the input instead.
String[] elements = input.split("[,\s]+");

String infraOrPolicyName = elements[0];
String infraOrPolicyParams = String.join(",", Arrays.copyOfRange(elements, 1, elements.length));
return new String[] { infraOrPolicyName, infraOrPolicyParams };
}
}