Commit 13dd61fb authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

Added example data for choreography EE resources

parent 8f65c716
......@@ -40,6 +40,8 @@ public class ChoreographyDetailPage extends BaseExtPage {
public static final String PREF_SERVICE_PAGINATOR_ROWS = "services.paginator.rows";
public static final String PREF_VM_PAGINATOR_ROWS = "virtualMachines.paginator.rows";
private final ChoreographyRestClient restClient;
private final String choreographyId;
......@@ -85,7 +87,7 @@ public class ChoreographyDetailPage extends BaseExtPage {
tabs.add(new AbstractTab(new ResourceModel("eeResources")) {
@Override
public WebMarkupContainer getPanel(final String panelId) {
return new EEResourcesPanel(panelId, choreography);
return new EEResourcesPanel(panelId, getPageReference(), choreographyId);
}
});
......
......@@ -15,12 +15,14 @@
*/
package org.apache.syncope.client.console.panels;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import java.io.Serializable;
import java.util.List;
import org.apache.syncope.client.console.rest.ChoreographyRestClient;
import org.apache.syncope.client.console.widgets.ResourceWidget;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.wicket.PageReference;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
......@@ -30,25 +32,58 @@ public class EEResourcesPanel extends Panel {
private final AnyObjectTO enactmentEngine;
public EEResourcesPanel(final String id, final ChoreographyTO choreography) {
private final EEStatisticBundle bundle;
public EEResourcesPanel(final String id, final PageReference pageRef, final String choreographyId) {
super(id);
this.restClient = new ChoreographyRestClient();
enactmentEngine = restClient.getChoreographyEE(choreography.getId());
this.enactmentEngine = restClient.getChoreographyEE(choreographyId);
this.bundle = new EEStatisticBundle(restClient.getEEVmList(enactmentEngine.getKey()));
add(new Label("eeName", getString("enactmentEngine") + " " + enactmentEngine.getName()));
RepeatingView resourcesOverview = new RepeatingView("resourceWidget");
resourcesOverview.add(new ResourceWidget(
resourcesOverview.newChildId(), "bg-yellow", 2, "Virtual Machines", "glyphicons glyphicons-server"));
resourcesOverview.add(new ResourceWidget(resourcesOverview.newChildId(), "bg-red", 8, "CPU", "fa fa-cloud"));
resourcesOverview.newChildId(),
"bg-yellow", bundle.virtualMachines, "Virtual Machines", "glyphicons glyphicons-server"));
resourcesOverview.add(new ResourceWidget(
resourcesOverview.newChildId(), "bg-red", bundle.cpus, "CPU", "fa fa-cloud"));
resourcesOverview.add(new ResourceWidget(
resourcesOverview.newChildId(), "bg-green", 4096, "RAM", "MB", "fa fa-cloud"));
resourcesOverview.newChildId(), "bg-green", bundle.ram, "RAM", "MB", "fa fa-cloud"));
resourcesOverview.add(new ResourceWidget(
resourcesOverview.newChildId(), "bg-aqua", 8, "Storage", "fa fa-database"));
resourcesOverview.newChildId(), "bg-aqua", bundle.storage, "Storage", "GB", "fa fa-database"));
add(resourcesOverview);
add(new EmptyPanel("virtualMachinesList"));
add(new VirtualMachinesDirectoryPanel("virtualMachinesList", pageRef, enactmentEngine.getKey()));
}
private class EEStatisticBundle implements Serializable {
private static final long serialVersionUID = 3856101339158216754L;
private int virtualMachines;
private int cpus;
private int ram;
private int storage;
EEStatisticBundle(final List<VirtualMachineInfoTO> vms) {
this.virtualMachines = 0;
this.cpus = 0;
this.ram = 0;
this.storage = 0;
for (VirtualMachineInfoTO vm: vms) {
this.virtualMachines ++;
this.cpus += vm.getCpuNumber();
this.ram += vm.getRam();
this.storage += vm.getStorage();
}
}
}
}
/*
* Copyright 2016 The CHOReVOLUTION project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.syncope.client.console.panels;
import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.apache.syncope.client.console.commons.DirectoryDataProvider;
import org.apache.syncope.client.console.pages.ChoreographyDetailPage;
import org.apache.syncope.client.console.panels.VirtualMachinesDirectoryPanel.VirtualMachinesDataProvider;
import org.apache.syncope.client.console.rest.ChoreographyRestClient;
import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
import org.apache.syncope.client.console.wizards.WizardMgtPanel;
import org.apache.wicket.PageReference;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;
public class VirtualMachinesDirectoryPanel extends DirectoryPanel<
VirtualMachineInfoTO, VirtualMachineInfoTO, VirtualMachinesDataProvider, ChoreographyRestClient> {
private static final long serialVersionUID = 3727444742501082182L;
private String enactmentEngineKey;
public VirtualMachinesDirectoryPanel(final String id, final PageReference pageRef,
final String enactmentEngineKey) {
super(id, new DirectoryPanel.Builder<VirtualMachineInfoTO, VirtualMachineInfoTO, ChoreographyRestClient>(
new ChoreographyRestClient(), pageRef) {
private static final long serialVersionUID = 4218621294354212530L;
@Override
protected WizardMgtPanel<VirtualMachineInfoTO> newInstance(final String id, final boolean wizardInModal) {
return new VirtualMachinesDirectoryPanel(id, this);
}
}.disableCheckBoxes());
this.enactmentEngineKey = enactmentEngineKey;
setFooterVisibility(true);
modal.addSubmitButton();
modal.size(Modal.Size.Large);
initResultTable();
}
private VirtualMachinesDirectoryPanel(
final String id,
final DirectoryPanel.Builder<VirtualMachineInfoTO, VirtualMachineInfoTO, ChoreographyRestClient> builder) {
super(id, builder);
}
@Override
protected VirtualMachinesDataProvider dataProvider() {
return new VirtualMachinesDataProvider(rows);
}
@Override
protected String paginatorRowsKey() {
return ChoreographyDetailPage.PREF_SERVICE_PAGINATOR_ROWS;
}
@Override
protected Collection<ActionLink.ActionType> getBulkActions() {
return Collections.<ActionLink.ActionType>emptyList();
}
@Override
protected List<IColumn<VirtualMachineInfoTO, String>> getColumns() {
final List<IColumn<VirtualMachineInfoTO, String>> columns = new ArrayList<>();
columns.add(new PropertyColumn<>(new ResourceModel("id"), "Id", "id"));
columns.add(new PropertyColumn<>(new ResourceModel("os"), "OS", "os"));
columns.add(new PropertyColumn<>(new ResourceModel("cpuNumber", "CPU"), "CPU", "cpuNumber"));
columns.add(new PropertyColumn<>(new ResourceModel("ram", "Memory (MB)"), "Memory (MB)", "ram"));
columns.add(new PropertyColumn<>(new ResourceModel("storage", "Storage (GB)"), "Storage (GB)", "storage"));
return columns;
}
protected final class VirtualMachinesDataProvider extends DirectoryDataProvider<VirtualMachineInfoTO> {
private static final long serialVersionUID = -185944053385660794L;
private final Comparator<VirtualMachineInfoTO> comparator;
private VirtualMachinesDataProvider(final int paginatorRows) {
super(paginatorRows);
comparator = new VMDataComparator();
}
@Override
public Iterator<VirtualMachineInfoTO> iterator(final long first, final long count) {
List<VirtualMachineInfoTO> list = restClient.getEEVmList(enactmentEngineKey);
//List<VirtualMachineInfoTO> list = this.getData();
Collections.sort(list, comparator);
return list.subList((int) first, (int) first + (int) count).iterator();
}
@Override
public long size() {
return restClient.getEEVmList(enactmentEngineKey).size();
//return this.getData().size();
}
@Override
public IModel<VirtualMachineInfoTO> model(final VirtualMachineInfoTO object) {
return new CompoundPropertyModel<>(object);
}
}
public static class VMDataComparator implements Comparator<VirtualMachineInfoTO>, Serializable {
private static final long serialVersionUID = 7394234509595556376L;
@Override
public int compare(final VirtualMachineInfoTO o1, final VirtualMachineInfoTO o2) {
return o1.getId().compareTo(o2.getId());
}
}
}
......@@ -23,6 +23,7 @@ import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.CoordinationDelegateTO;
import eu.chorevolution.idm.common.to.ServiceTO;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import eu.chorevolution.idm.common.types.ChoreographyAction;
import java.util.List;
import org.apache.syncope.common.lib.to.AnyObjectTO;
......@@ -125,4 +126,8 @@ public class ChoreographyRestClient extends BaseRestClient {
public AnyObjectTO getChoreographyEE(final String choreographyId) {
return getService(ChoreographyService.class).getEnactmentEngine(choreographyId);
}
public List<VirtualMachineInfoTO> getEEVmList(final String enactmentEngineKey) {
return getService(ChoreographyService.class).getEEVmList(enactmentEngineKey);
}
}
......@@ -44,7 +44,11 @@ public class ResourceWidget extends BaseWidget {
box.add(new Label("number", number));
box.add(new Label("label", label));
box.add(new Label("unit", unit));
if (!unit.equals("")) {
box.add(new Label("unit", " (" + unit + ")"));
} else {
box.add(new Label("unit", ""));
}
Label iconLabel = new Label("icon");
iconLabel.add(new AttributeAppender("class", icon));
......
......@@ -25,3 +25,4 @@ network_business_overhead=Network Overhead For Business Messages Exchange Time
service_execution_time=Service Execution time
cd=CD
averageInstance=Average Data
choreographies=Choreographies
......@@ -25,3 +25,4 @@ network_business_overhead=Network Overhead For Business Messages Exchange Time
service_execution_time=Service Execution time
cd=CD
averageInstance=Dati Medi
choreographies=Coreografie
......@@ -25,3 +25,4 @@ network_business_overhead=Network Overhead For Business Messages Exchange Time
service_execution_time=Service Execution time
cd=CD
averageInstance=Dados M\u00e9dios
choreographies=Coreografias
......@@ -20,6 +20,7 @@ limitations under the License.
<div class="row">
<span wicket:id="resourceWidget"/>
</div>
<h3><wicket:message key="virtualMachines"/></h3>
<div wicket:id="virtualMachinesList"/>
</wicket:panel>
</html>
......@@ -14,3 +14,4 @@
# limitations under the License.
#
enactmentEngine=Enactment Engine
virtualMachines=Virtual Machines
......@@ -14,3 +14,4 @@
# limitations under the License.
#
enactmentEngine=Enactment Engine
virtualMachines=Macchine Virtuali
......@@ -14,3 +14,4 @@
# limitations under the License.
#
enactmentEngine=Enactment Engine
virtualMachines=M\u00e1quinas virtuais
......@@ -37,8 +37,8 @@ under the License.
<div class="col-lg-3 col-xs-6">
<div wicket:id="box" class="small-box">
<div class="inner">
<h3><span wicket:id="number"/><span wicket:id="unit"/></h3>
<p><span wicket:id="label"/></p>
<h3><span wicket:id="number"/></h3>
<p><span wicket:id="label"/><span wicket:id="unit"/></p>
</div>
<div class="icon" style="cursor: pointer;">
<i wicket:id="icon"></i>
......
/*
* Copyright 2016 The CHOReVOLUTION project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.chorevolution.idm.common.to;
import org.apache.syncope.common.lib.AbstractBaseBean;
public class VirtualMachineInfoTO extends AbstractBaseBean {
private static final long serialVersionUID = 3612465719052681573L;
private String id;
private int cpuNumber;
private int ram;
private int storage;
private String os;
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public int getCpuNumber() {
return cpuNumber;
}
public void setCpuNumber(final int cpuNumber) {
this.cpuNumber = cpuNumber;
}
public int getRam() {
return ram;
}
public void setRam(final int ram) {
this.ram = ram;
}
public int getStorage() {
return storage;
}
public void setStorage(final int storage) {
this.storage = storage;
}
public String getOs() {
return os;
}
public void setOs(final String os) {
this.os = os;
}
}
......@@ -22,6 +22,7 @@ import eu.chorevolution.chors.ChorSpecUtils;
import eu.chorevolution.datamodel.Choreography;
import eu.chorevolution.datamodel.ExistingService;
import eu.chorevolution.idm.common.ChorevolutionEntitlement;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import eu.chorevolution.idm.common.types.ChoreographyAction;
import eu.chorevolution.idm.common.types.ChoreographyOperation;
import eu.chorevolution.idm.common.types.SecurityFilterInfo;
......@@ -772,6 +773,30 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
return enactmentEngineForChoreography(choreography.getKey());
}
// This is a temporary method
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_LIST + "')")
public List<VirtualMachineInfoTO> getEEVmList(final String enactmentEngineKey) {
List<VirtualMachineInfoTO> list = new ArrayList<>();
VirtualMachineInfoTO info1 = new VirtualMachineInfoTO();
info1.setId("vm001");
info1.setOs("Ubuntu 16.10");
info1.setCpuNumber(4);
info1.setRam(4096);
info1.setStorage(512);
list.add(info1);
VirtualMachineInfoTO info2 = new VirtualMachineInfoTO();
info2.setId("vm002");
info2.setOs("Ubuntu 16.10");
info2.setCpuNumber(2);
info2.setRam(2048);
info2.setStorage(1000);
list.add(info2);
return list;
}
@Override
protected AbstractBaseBean resolveReference(final Method method, final Object... args)
throws UnresolvedReferenceException {
......
......@@ -15,12 +15,14 @@
*/
package org.apache.syncope.common.rest.api.service;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import eu.chorevolution.idm.common.types.ChoreographyAction;
import eu.chorevolution.idm.common.types.ChoreographyOperation;
import eu.chorevolution.idm.common.types.SecurityFilterInfo;
import eu.chorevolution.idm.common.types.ServiceAction;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
......@@ -174,4 +176,14 @@ public interface ChoreographyService extends JAXRSService {
@GET
@Path("{id}/enactmentEngine")
AnyObjectTO getEnactmentEngine(@NotNull @PathParam("id") String id);
/**
* Returns the enactment engine associated to the choreography
*
* @param enactmentEngineKey enactment engine key
* @return list of virtual machines for the enactment engine
*/
@GET
@Path("enactmentEngine/{id}/virtualMachienes")
List<VirtualMachineInfoTO> getEEVmList(@NotNull @PathParam("id") String enactmentEngineKey);
}
......@@ -15,6 +15,7 @@
*/
package org.apache.syncope.core.rest.cxf.service;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import eu.chorevolution.idm.common.types.ChoreographyAction;
import eu.chorevolution.idm.common.types.ChoreographyOperation;
import eu.chorevolution.idm.common.types.SecurityFilterInfo;
......@@ -22,6 +23,7 @@ import eu.chorevolution.idm.common.types.ServiceAction;
import org.apache.syncope.core.logic.ChoreographyLogic;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import javax.ws.rs.core.Response;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.rest.api.service.ChoreographyService;
......@@ -96,4 +98,10 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
return logic.getChoreographyEnactmentEngine(choreographyId);
}
@Override
public List<VirtualMachineInfoTO> getEEVmList(final String enactmentEngineKey) {
return logic.getEEVmList(enactmentEngineKey);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment