use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class DeleteGroups method deleteGroups.
/**
* Delete (sub)groups of any group or VO.
*
* @param groups groups to be deleted
* @param force TRUE = forced delete (remove all members, remove from resources) / FALSE = not delete if group has members
*/
public void deleteGroups(final ArrayList<? extends Group> groups, boolean force) {
// whole JSON query
JSONObject jsonQuery = new JSONObject();
JSONArray grps = new JSONArray();
for (int i = 0; i < groups.size(); i++) {
grps.set(i, new JSONNumber(groups.get(i).getId()));
}
jsonQuery.put("groups", grps);
jsonQuery.put("forceDelete", new JSONNumber((force) ? 1 : 0));
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Deleting groups failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Groups successfully deleted!");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class ForceServicePropagation method forcePropagation.
/**
* Starts Force service propagation for specified service and facility
*
* @param facilityId ID of facility to propagate service to
* @param serviceId ID of service to be propagated
*/
public void forcePropagation(final int facilityId, final int serviceId) {
this.facilityId = facilityId;
this.serviceId = serviceId;
// test arguments
if (!this.testArguments()) {
return;
}
// whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("facility", new JSONNumber(facilityId));
jsonQuery.put("service", new JSONNumber(serviceId));
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Propagation initialization of service: " + serviceId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Propagation of service: " + serviceId + " initiated.");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class InsertExecService method addExecService.
/**
* Creates exec service in DB and associate it with service
*
* @param service service to associate with
* @param type type of exec service (SEND, GENERATE)
* @param enabled true if exec service is enabled
* @param delayNum default delay
* @param scriptPath path to propagation scripts
*/
public void addExecService(Service service, String type, Boolean enabled, int delayNum, String scriptPath) {
// TODO - test input
// test arguments
// if(!this.testArguments()){
// return;
//}
// reconstruct service
JSONObject serv = new JSONObject();
serv.put("id", new JSONNumber(service.getId()));
serv.put("name", new JSONString(service.getName()));
// reconstruct exec service
JSONObject exec = new JSONObject();
exec.put("execServiceType", new JSONString(type));
exec.put("enabled", JSONBoolean.getInstance(enabled));
exec.put("defaultDelay", new JSONNumber(delayNum));
// insert service into exec service
exec.put("service", serv);
exec.put("script", new JSONString(scriptPath));
// whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("execService", exec);
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Adding of exec service failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Exec service successfully added!");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class RemoveHosts method removeHost.
/**
* Removes host from cluster in DB - make RPC call
*
* @param hostId ID of host to be removed
*/
public void removeHost(final int hostId) {
this.hostId = hostId;
// test arguments
if (!this.testDeleting()) {
return;
}
// json object
JSONObject jsonQuery = prepareJSONObject();
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Removing host: " + hostId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Host: " + hostId + " removed!");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class RemoveOwner method removeFacilityOwner.
/**
* Attempts to remove admin from facility
*
* @param facilityId id of facility
* @param ownerId ID of user which should be removed as admin
*/
public void removeFacilityOwner(final int facilityId, final int ownerId) {
this.ownerId = ownerId;
this.facilityId = facilityId;
// test arguments
if (!this.testRemoving()) {
return;
}
// prepare json object
JSONObject jsonQuery = prepareJSONObject();
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Removing owner (" + ownerId + ") from facility: " + facilityId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Owner (" + ownerId + ") removed from facility: " + facilityId);
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
Aggregations