git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/resource-management/quota-manager@142703 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
78e50b04fb
commit
45e3a42c37
|
@ -72,8 +72,12 @@ public class QuotaCheck {
|
||||||
DiscoveryListUser discoveryListUser= new DiscoveryListUser(this.context);
|
DiscoveryListUser discoveryListUser= new DiscoveryListUser(this.context);
|
||||||
log.debug("QuotaCheck - for context:{} , list user:{}",context,discoveryListUser.getListUser());
|
log.debug("QuotaCheck - for context:{} , list user:{}",context,discoveryListUser.getListUser());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//verify for each user if have a specify quota and Overwrite if exist and traduce into object for query accounting
|
//verify for each user if have a specify quota and Overwrite if exist and traduce into object for query accounting
|
||||||
quotaUtility.verifyListUser(discoveryListUser.getListUser());
|
quotaUtility.verifyListUser(discoveryListUser.getListUser());
|
||||||
|
|
||||||
log.debug("QuotaCheck - quotaUtility.getUsageToBeVerified():{}",quotaUtility.getUsageToBeVerified());
|
log.debug("QuotaCheck - quotaUtility.getUsageToBeVerified():{}",quotaUtility.getUsageToBeVerified());
|
||||||
|
|
||||||
Boolean error=true;
|
Boolean error=true;
|
||||||
|
@ -100,12 +104,12 @@ public class QuotaCheck {
|
||||||
//insert into db
|
//insert into db
|
||||||
for(UsageValue usageIndex:quotaUtility.getUsageToBeVerified()){
|
for(UsageValue usageIndex:quotaUtility.getUsageToBeVerified()){
|
||||||
if (usageIndex.getClz()==QuotaType.STORAGE.getQuotaTypeClass()){
|
if (usageIndex.getClz()==QuotaType.STORAGE.getQuotaTypeClass()){
|
||||||
log.debug("save quota storage identifier:{},temporalConstraint:{}",usageIndex.getIdentifier(),usageIndex.getTemporalConstraint());
|
log.debug("----Elaborate a identifier:{}, temporalConstraint:{} , insert a quota storage",usageIndex.getIdentifier(),usageIndex.getTemporalConstraint());
|
||||||
QuotaUsageStorageValue usageStorVal=(QuotaUsageStorageValue) usageIndex;
|
QuotaUsageStorageValue usageStorVal=(QuotaUsageStorageValue) usageIndex;
|
||||||
queryQuotaUsage.insertStorageQuota(usageStorVal);
|
queryQuotaUsage.insertStorageQuota(usageStorVal);
|
||||||
}
|
}
|
||||||
if (usageIndex.getClz()==QuotaType.SERVICE.getQuotaTypeClass()){
|
if (usageIndex.getClz()==QuotaType.SERVICE.getQuotaTypeClass()){
|
||||||
log.debug("save quota service identifier:{},temporalConstraint:{}",usageIndex.getIdentifier(),usageIndex.getTemporalConstraint());
|
log.debug("----Elaborate a identifier:{}, temporalConstraint:{} , insert a quota service",usageIndex.getIdentifier(),usageIndex.getTemporalConstraint());
|
||||||
QuotaUsageServiceValue usageSerVal=(QuotaUsageServiceValue) usageIndex;
|
QuotaUsageServiceValue usageSerVal=(QuotaUsageServiceValue) usageIndex;
|
||||||
queryQuotaUsage.insertServiceQuota(usageSerVal);
|
queryQuotaUsage.insertServiceQuota(usageSerVal);
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class QuotaUsage {
|
||||||
|
|
||||||
Double percent=((usageStorVal.getD()/usageStorVal.getdQuota())*100);
|
Double percent=((usageStorVal.getD()/usageStorVal.getdQuota())*100);
|
||||||
percent=Math.round(percent * 100.0) / 100.0;
|
percent=Math.round(percent * 100.0) / 100.0;
|
||||||
log.debug("Quota Percent quota:{} used:{},use:{}",usageStorVal.getdQuota(),usageStorVal.getD(),percent);
|
log.debug("Quota Percent quota:{} used:{} percent:{}",usageStorVal.getdQuota(),usageStorVal.getD(),percent);
|
||||||
|
|
||||||
String queryVerify="SELECT NOTIFICATIONWARNING1,NOTIFICATIONWARNING2,NOTIFICATIONEXCEED,QUOTAASSIGNED FROM "+ConstantsDb.DATABASE_PREFIX+ConstantsDb.SEPARATOR+ConstantsDb.DATABASE_TYPE_STORAGE+ConstantsDb.SEPARATOR+periodQuota+""
|
String queryVerify="SELECT NOTIFICATIONWARNING1,NOTIFICATIONWARNING2,NOTIFICATIONEXCEED,QUOTAASSIGNED FROM "+ConstantsDb.DATABASE_PREFIX+ConstantsDb.SEPARATOR+ConstantsDb.DATABASE_TYPE_STORAGE+ConstantsDb.SEPARATOR+periodQuota+""
|
||||||
+ " WHERE IDENTIFIER ='"+usageStorVal.getIdentifier()+"'";
|
+ " WHERE IDENTIFIER ='"+usageStorVal.getIdentifier()+"'";
|
||||||
|
@ -154,32 +154,37 @@ public class QuotaUsage {
|
||||||
quotaAssignedOld= rs.getDouble("QUOTAASSIGNED");
|
quotaAssignedOld= rs.getDouble("QUOTAASSIGNED");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quotaAssignedOld!=usageStorVal.getdQuota()){
|
if (!quotaAssignedOld.equals(usageStorVal.getdQuota())){
|
||||||
//verify if your quota assigned is changed
|
//verify if your quota assigned is changed
|
||||||
log.debug("quota changed old value:{} new value:{}",quotaAssignedOld,usageStorVal.getdQuota());
|
log.debug("quota changed old value:{} new value:{}",quotaAssignedOld,usageStorVal.getdQuota());
|
||||||
|
if (!quotaAssignedOld.equals(0.0)){
|
||||||
|
//verify if your old quota is consistent
|
||||||
|
log.debug("your old quota is consistent:{}",quotaAssignedOld);
|
||||||
|
sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"change");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//verify if a getdQuota() == -1 considery a infinity quota
|
if (!usageStorVal.getdQuota().equals(-1)){
|
||||||
|
|
||||||
log.debug("usageStorVal.getdQuota()!=-1 :"+usageStorVal.getdQuota());
|
|
||||||
if (usageStorVal.getdQuota()!=-1){
|
|
||||||
|
|
||||||
if ((percent>Constants.LIMIT_MSG_QUOTA_PERC_USAGE_1)&&(percent<Constants.LIMIT_MSG_QUOTA_PERC_USAGE_2)){
|
if ((percent>Constants.LIMIT_MSG_QUOTA_PERC_USAGE_1)&&(percent<Constants.LIMIT_MSG_QUOTA_PERC_USAGE_2)){
|
||||||
//verify if your quota is between 90 and 95 % first warning
|
//verify if your quota is between 90 and 95 % first warning
|
||||||
if (!notificationWarning1){
|
if (!notificationWarning1){
|
||||||
sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"warning");
|
if (sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"warning")){
|
||||||
notificationWarning1=true;
|
log.debug("notification Send! warning level1");
|
||||||
notificationWarning2=false;
|
notificationWarning1=true;
|
||||||
notificationExceed=false;
|
notificationWarning2=false;
|
||||||
|
notificationExceed=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((percent>Constants.LIMIT_MSG_QUOTA_PERC_USAGE_2)&&(percent<100)){
|
else if ((percent>Constants.LIMIT_MSG_QUOTA_PERC_USAGE_2)&&(percent<100)){
|
||||||
//verify if your quota is between 95 and 100 % second warning
|
//verify if your quota is between 95 and 100 % second warning
|
||||||
if (!notificationWarning2){
|
if (!notificationWarning2){
|
||||||
sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"warning");
|
if (sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"warning")){
|
||||||
|
log.debug("notification Send! warning level2");
|
||||||
notificationWarning2=true;
|
notificationWarning2=true;
|
||||||
notificationExceed=false;
|
notificationExceed=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((percent>=100)){
|
else if ((percent>=100)){
|
||||||
|
@ -187,10 +192,11 @@ public class QuotaUsage {
|
||||||
log.debug("Quota exceed for:{} identifier:{} notification:{} ",percent,usageStorVal.getIdentifier(),notificationExceed);
|
log.debug("Quota exceed for:{} identifier:{} notification:{} ",percent,usageStorVal.getIdentifier(),notificationExceed);
|
||||||
|
|
||||||
if (!notificationExceed){
|
if (!notificationExceed){
|
||||||
sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"exceed");
|
if(sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"exceed")){
|
||||||
|
log.debug("notification Send! warning level3");
|
||||||
|
notificationExceed=true;
|
||||||
|
}
|
||||||
userExceedQuota.add(usageStorVal.getIdentifier());
|
userExceedQuota.add(usageStorVal.getIdentifier());
|
||||||
notificationExceed=true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (notificationWarning1 || notificationWarning2 || notificationExceed){
|
else if (notificationWarning1 || notificationWarning2 || notificationExceed){
|
||||||
|
@ -199,13 +205,18 @@ public class QuotaUsage {
|
||||||
usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD());
|
usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD());
|
||||||
log.debug("---Quota reset for notificationWarning1:{} and notificationWarning2 :{} and notificationExceed:{}",
|
log.debug("---Quota reset for notificationWarning1:{} and notificationWarning2 :{} and notificationExceed:{}",
|
||||||
notificationWarning1,notificationWarning2,notificationExceed);
|
notificationWarning1,notificationWarning2,notificationExceed);
|
||||||
sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"reset");
|
if(sendNotification.sendNotificationUser(usageStorVal.getIdentifier(),usageStorVal.getdQuota(),usageStorVal.getD(),percent,"reset")){
|
||||||
notificationWarning1=false;
|
log.debug("reset notification Send!");
|
||||||
notificationWarning2=false;
|
notificationWarning1=false;
|
||||||
notificationExceed=false;
|
notificationWarning2=false;
|
||||||
|
notificationExceed=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
log.debug("quote infinite for identifier:{}",usageStorVal.getIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
queryVerify="SELECT count(*) FROM "+ConstantsDb.DATABASE_PREFIX+ConstantsDb.SEPARATOR+ConstantsDb.DATABASE_TYPE_STORAGE+ConstantsDb.SEPARATOR+periodQuota+""
|
queryVerify="SELECT count(*) FROM "+ConstantsDb.DATABASE_PREFIX+ConstantsDb.SEPARATOR+ConstantsDb.DATABASE_TYPE_STORAGE+ConstantsDb.SEPARATOR+periodQuota+""
|
||||||
+ " WHERE IDENTIFIER ='"+usageStorVal.getIdentifier()+"'";
|
+ " WHERE IDENTIFIER ='"+usageStorVal.getIdentifier()+"'";
|
||||||
|
@ -257,7 +268,13 @@ public class QuotaUsage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* selectStorageQuota
|
||||||
|
* @param identifier
|
||||||
|
* @param interval
|
||||||
|
* @return Quota Storage Status
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public QuotaStorageStatus selectStorageQuota(String identifier, TimeInterval interval)throws Exception {
|
public QuotaStorageStatus selectStorageQuota(String identifier, TimeInterval interval)throws Exception {
|
||||||
|
|
||||||
Connection connection = getDBConnection();
|
Connection connection = getDBConnection();
|
||||||
|
@ -294,8 +311,6 @@ public class QuotaUsage {
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
return quotaStorageStatus;
|
return quotaStorageStatus;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -321,8 +336,8 @@ public class QuotaUsage {
|
||||||
* @return connection
|
* @return connection
|
||||||
*/
|
*/
|
||||||
private Connection getDBConnection() {
|
private Connection getDBConnection() {
|
||||||
Connection dbConnection = null;
|
|
||||||
|
|
||||||
|
Connection dbConnection = null;
|
||||||
try {
|
try {
|
||||||
Class.forName(ConstantsDb.DB_DRIVER);
|
Class.forName(ConstantsDb.DB_DRIVER);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
|
|
@ -34,11 +34,17 @@ public class DiscoveryConfiguration {
|
||||||
private String textQuotaUserExceedSubject="ATTENTION Your storage space exceeds the assigned quota capacity";
|
private String textQuotaUserExceedSubject="ATTENTION Your storage space exceeds the assigned quota capacity";
|
||||||
private String textQuotaUserExceed="Hi {identifier}, your storage space is full, Your quota occupation is {percent}% , you are using {quotaUsage} out of {quotaAssigned} available. Please free up some space.";
|
private String textQuotaUserExceed="Hi {identifier}, your storage space is full, Your quota occupation is {percent}% , you are using {quotaUsage} out of {quotaAssigned} available. Please free up some space.";
|
||||||
|
|
||||||
|
private String textQuotaUserChangeSubject="INFO your quota has changed";
|
||||||
|
private String textQuotaUserChange="Hi {identifier},your quota has changed to {quotaAssigned}. Your are currently occupying {percent}% of the available space.";
|
||||||
|
|
||||||
|
|
||||||
private String textQuotaAdminExceedSubject="INFO List User quota Exceed";
|
private String textQuotaAdminExceedSubject="INFO List User quota Exceed";
|
||||||
private String textQuotaAdminExceed="Dear, now this user have a quota exceed: {listuser}";
|
private String textQuotaAdminExceed="Dear, now this user have a quota exceed: {listuser}";
|
||||||
|
|
||||||
private String textQuotaUserReset="Hi {identifier}, Your quota occupation decreased and is now {percent}%, you are using {quotaUsage}, out of {quotaAssigned} available. Good job!";
|
private String textQuotaUserReset="Hi {identifier}, Your quota occupation decreased and is now {percent}%, you are using {quotaUsage}, out of {quotaAssigned} available. Good job!";
|
||||||
private String textQuotaUserResetSubject="INFO Your storage space is now sufficiently below the quota capacity";
|
private String textQuotaUserResetSubject="INFO Your storage space is now sufficiently below the quota capacity";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String roleNotifier="Administrator";
|
private String roleNotifier="Administrator";
|
||||||
|
|
||||||
|
@ -57,6 +63,9 @@ public class DiscoveryConfiguration {
|
||||||
private final static String TEXT_QUOTA_USER_EXCEED_SUBJECT="textQuotaUserExceedSubject";
|
private final static String TEXT_QUOTA_USER_EXCEED_SUBJECT="textQuotaUserExceedSubject";
|
||||||
private final static String TEXT_QUOTA_USER_EXCEED="textQuotaUserExceed";
|
private final static String TEXT_QUOTA_USER_EXCEED="textQuotaUserExceed";
|
||||||
|
|
||||||
|
private final static String TEXT_QUOTA_USER_CHANGE_SUBJECT="textQuotaUserChangeSubject";
|
||||||
|
private final static String TEXT_QUOTA_USER_CHANGE="textQuotaUserChange";
|
||||||
|
|
||||||
private final static String TEXT_QUOTA_ADMIN_EXCEED_SUBJECT="textQuotaAdminExceedSubject";
|
private final static String TEXT_QUOTA_ADMIN_EXCEED_SUBJECT="textQuotaAdminExceedSubject";
|
||||||
private final static String TEXT_QUOTA_ADMIN_EXCEED="textQuotaAdminExceed";
|
private final static String TEXT_QUOTA_ADMIN_EXCEED="textQuotaAdminExceed";
|
||||||
|
|
||||||
|
@ -153,6 +162,12 @@ public class DiscoveryConfiguration {
|
||||||
case TEXT_QUOTA_USER_EXCEED:
|
case TEXT_QUOTA_USER_EXCEED:
|
||||||
textQuotaUserExceed=value;
|
textQuotaUserExceed=value;
|
||||||
break;
|
break;
|
||||||
|
case TEXT_QUOTA_USER_CHANGE_SUBJECT:
|
||||||
|
textQuotaUserChangeSubject=value;
|
||||||
|
break;
|
||||||
|
case TEXT_QUOTA_USER_CHANGE:
|
||||||
|
textQuotaUserChange=value;
|
||||||
|
break;
|
||||||
case TEXT_QUOTA_ADMIN_EXCEED_SUBJECT:
|
case TEXT_QUOTA_ADMIN_EXCEED_SUBJECT:
|
||||||
textQuotaAdminExceedSubject=value;
|
textQuotaAdminExceedSubject=value;
|
||||||
break;
|
break;
|
||||||
|
@ -182,13 +197,25 @@ public class DiscoveryConfiguration {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "DiscoveryConfiguration [databasePath=" + databasePath
|
return "DiscoveryConfiguration [databasePath=" + databasePath
|
||||||
+ ", usernameDb=" + usernameDb + ", pwdnameDb=" + pwdnameDb
|
+ ", usernameDb=" + usernameDb + ", pwdnameDb=" + pwdnameDb
|
||||||
+ ", dbname=" + dbname + ", notifierUser=" + notifierUser
|
+ ", dbname=" + dbname + ", notifierUser=" + notifierUser
|
||||||
+ ", notifierAdmin=" + notifierAdmin + ", refreshTimeQuota="
|
+ ", notifierAdmin=" + notifierAdmin + ", refreshTimeQuota="
|
||||||
+ refreshTimeQuota + "]";
|
+ refreshTimeQuota + ", textQuotaUserWarning="
|
||||||
|
+ textQuotaUserWarning + ", textQuotaUserWarningSubject="
|
||||||
|
+ textQuotaUserWarningSubject + ", textQuotaUserExceedSubject="
|
||||||
|
+ textQuotaUserExceedSubject + ", textQuotaUserExceed="
|
||||||
|
+ textQuotaUserExceed + ", textQuotaUserChangeSubject="
|
||||||
|
+ textQuotaUserChangeSubject + ", textQuotaUserChange="
|
||||||
|
+ textQuotaUserChange + ", textQuotaAdminExceedSubject="
|
||||||
|
+ textQuotaAdminExceedSubject + ", textQuotaAdminExceed="
|
||||||
|
+ textQuotaAdminExceed + ", textQuotaUserReset="
|
||||||
|
+ textQuotaUserReset + ", textQuotaUserResetSubject="
|
||||||
|
+ textQuotaUserResetSubject + ", roleNotifier=" + roleNotifier
|
||||||
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDatabasePath() {
|
public String getDatabasePath() {
|
||||||
|
@ -251,5 +278,16 @@ public class DiscoveryConfiguration {
|
||||||
public String getRoleNotifier() {
|
public String getRoleNotifier() {
|
||||||
return roleNotifier;
|
return roleNotifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTextQuotaUserChangeSubject() {
|
||||||
|
return textQuotaUserChangeSubject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTextQuotaUserChange() {
|
||||||
|
return textQuotaUserChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -22,10 +23,17 @@ import com.google.gson.Gson;
|
||||||
public class DiscoveryListUser {
|
public class DiscoveryListUser {
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(DiscoveryListUser.class);
|
private static Logger log = LoggerFactory.getLogger(DiscoveryListUser.class);
|
||||||
private final static String NAME_SERVICE_ALL_USERNAMES = "2/users/get-all-usernames?gcube-token";
|
//private final static String NAME_SERVICE_ALL_USERNAMES = "2/users/get-all-usernames?gcube-token";
|
||||||
|
|
||||||
|
private final static String NAME_SERVICE_ALL_USERNAMES = "2/users/get-all-fullnames-and-usernames?gcube-token";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<String> listUser = null;
|
private List<String> listUser = null;
|
||||||
|
|
||||||
|
private static Map<String, String> listFullUser;
|
||||||
|
|
||||||
public DiscoveryListUser(String context) {
|
public DiscoveryListUser(String context) {
|
||||||
|
|
||||||
String token =SecurityTokenProvider.instance.get();
|
String token =SecurityTokenProvider.instance.get();
|
||||||
|
@ -34,13 +42,13 @@ public class DiscoveryListUser {
|
||||||
String urlService=discoveryList.getBasePath()+NAME_SERVICE_ALL_USERNAMES+"="+token;
|
String urlService=discoveryList.getBasePath()+NAME_SERVICE_ALL_USERNAMES+"="+token;
|
||||||
log.debug("service DiscoveryServiceListUser:"+urlService);
|
log.debug("service DiscoveryServiceListUser:"+urlService);
|
||||||
String data = getJSON(urlService);
|
String data = getJSON(urlService);
|
||||||
log.debug("data read:{}",data);
|
//log.debug("data read:{}",data);
|
||||||
ListUser msg = new Gson().fromJson(data, ListUser.class);
|
ListUserInfo msg = new Gson().fromJson(data, ListUserInfo.class);
|
||||||
|
listFullUser=msg.getResult();
|
||||||
//TODO for debug limit a list user:
|
listUser = new ArrayList<String>(listFullUser.keySet());
|
||||||
//listUser=msg.getResult();
|
log.debug("listuser:{}",listUser);
|
||||||
//REMOVE TODO
|
//ONLY DEBUG
|
||||||
|
/*
|
||||||
listUser=new ArrayList<String>();
|
listUser=new ArrayList<String>();
|
||||||
listUser.add("lucio.lelii");
|
listUser.add("lucio.lelii");
|
||||||
listUser.add("alessandro.pieve");
|
listUser.add("alessandro.pieve");
|
||||||
|
@ -49,6 +57,8 @@ public class DiscoveryListUser {
|
||||||
listUser.add("costantino.perciante");
|
listUser.add("costantino.perciante");
|
||||||
listUser.add("luca.frosini");
|
listUser.add("luca.frosini");
|
||||||
listUser.add("roberto.cirillo");
|
listUser.add("roberto.cirillo");
|
||||||
|
log.debug("list username:{}",listUser);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,6 +69,12 @@ public class DiscoveryListUser {
|
||||||
return listUser;
|
return listUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getMapUser(String identifier) {
|
||||||
|
return listFullUser.get(identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param url
|
* @param url
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.gcube.resource.management.quota.manager.util;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author pieve
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ListUserInfo {
|
||||||
|
/*
|
||||||
|
"success" : false,
|
||||||
|
"message" : "String index out of range: 5",
|
||||||
|
"result" : null
|
||||||
|
*/
|
||||||
|
private Boolean success;
|
||||||
|
private String message;
|
||||||
|
private Map<String, String> result;
|
||||||
|
public Boolean getSuccess() {
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
public void setSuccess(Boolean success) {
|
||||||
|
this.success = success;
|
||||||
|
}
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
public Map<String, String> getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public void setResult(Map<String, String> result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -34,7 +34,7 @@ public class SendNotification {
|
||||||
|
|
||||||
private DiscoveryConfiguration discoveryCheck;
|
private DiscoveryConfiguration discoveryCheck;
|
||||||
private final static String WRITE_MESSAGE = "2/messages/write-message";
|
private final static String WRITE_MESSAGE = "2/messages/write-message";
|
||||||
private final static String NAME_USERNAME_GLOBAL_ROLE = "2/users/get-usernames-by-global-role?role-name=Administrator&gcube-token";
|
//private final static String NAME_USERNAME_GLOBAL_ROLE = "2/users/get-usernames-by-global-role?role-name=Administrator&gcube-token";
|
||||||
private static Logger log = LoggerFactory.getLogger(QuotaUsage.class);
|
private static Logger log = LoggerFactory.getLogger(QuotaUsage.class);
|
||||||
|
|
||||||
public SendNotification(DiscoveryConfiguration discoveryCheck){
|
public SendNotification(DiscoveryConfiguration discoveryCheck){
|
||||||
|
@ -51,9 +51,10 @@ public class SendNotification {
|
||||||
this.percent=percent;
|
this.percent=percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendNotificationUser(String identifier, Double quotaAssigned, Double quotaUsage, Double percent, String type) throws JSONException{
|
public boolean sendNotificationUser(String identifier, Double quotaAssigned, Double quotaUsage, Double percent, String type) throws JSONException{
|
||||||
|
Boolean resultSend= false;
|
||||||
if (discoveryCheck.getNotifierUser()){
|
if (discoveryCheck.getNotifierUser()){
|
||||||
Boolean resultSend= false;
|
|
||||||
configure(identifier, quotaAssigned, quotaUsage, percent);
|
configure(identifier, quotaAssigned, quotaUsage, percent);
|
||||||
log.debug("Notification Quota limit used:{} identifier:{} quotaAssigned:{} quotaUsage:{} ",this.percent,this.identifier,this.quotaAssigned,this.quotaUsage);
|
log.debug("Notification Quota limit used:{} identifier:{} quotaAssigned:{} quotaUsage:{} ",this.percent,this.identifier,this.quotaAssigned,this.quotaUsage);
|
||||||
|
|
||||||
|
@ -71,18 +72,20 @@ public class SendNotification {
|
||||||
body=CleanNotification(discoveryCheck.getTextQuotaUserReset());
|
body=CleanNotification(discoveryCheck.getTextQuotaUserReset());
|
||||||
subject=discoveryCheck.getTextQuotaUserResetSubject();
|
subject=discoveryCheck.getTextQuotaUserResetSubject();
|
||||||
}
|
}
|
||||||
|
if (type=="change"){
|
||||||
|
body=CleanNotification(discoveryCheck.getTextQuotaUserChange());
|
||||||
|
subject=discoveryCheck.getTextQuotaUserChangeSubject();
|
||||||
|
}
|
||||||
String token = SecurityTokenProvider.instance.get();
|
String token = SecurityTokenProvider.instance.get();
|
||||||
JSONObject urlParameters = new JSONObject();
|
JSONObject urlParameters = new JSONObject();
|
||||||
List<String> user=new ArrayList<String>();
|
List<String> user=new ArrayList<String>();
|
||||||
//TODO delete
|
user.add("alessandro.pieve");
|
||||||
//user.add("alessandro.pieve");
|
//user.add(identifier);
|
||||||
user.add(identifier);
|
|
||||||
|
|
||||||
urlParameters.put("recipients", user);
|
urlParameters.put("recipients", user);
|
||||||
urlParameters.put("body", body);
|
urlParameters.put("body", body);
|
||||||
urlParameters.put("subject", subject);
|
urlParameters.put("subject", subject);
|
||||||
try {
|
try {
|
||||||
resultSend = writeMsg(urlService, urlParameters,token);
|
resultSend = writeMsg(urlService, urlParameters,token);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -91,7 +94,7 @@ public class SendNotification {
|
||||||
else{
|
else{
|
||||||
log.debug("Not notification Quota limit used:{} identifier:{} quotaAssigned:{} quotaUsage:{} ",percent,identifier,quotaAssigned,quotaUsage);
|
log.debug("Not notification Quota limit used:{} identifier:{} quotaAssigned:{} quotaUsage:{} ",percent,identifier,quotaAssigned,quotaUsage);
|
||||||
}
|
}
|
||||||
|
return resultSend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,17 +103,18 @@ public class SendNotification {
|
||||||
* @param userExceedQuota
|
* @param userExceedQuota
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void SendNotificationAdmin(List<String> userExceedQuota) throws Exception{
|
public boolean SendNotificationAdmin(List<String> userExceedQuota) throws Exception{
|
||||||
log.debug("SendNotificationAdmin for user:{}",userExceedQuota.toString());
|
log.debug("SendNotificationAdmin for user:{}",userExceedQuota.toString());
|
||||||
|
Boolean resultSend= false;
|
||||||
if (userExceedQuota.size()>0){
|
if (userExceedQuota.size()>0){
|
||||||
if (discoveryCheck.getNotifierAdmin()){
|
if (discoveryCheck.getNotifierAdmin()){
|
||||||
|
|
||||||
Boolean resultSend= false;
|
|
||||||
String token = SecurityTokenProvider.instance.get();
|
String token = SecurityTokenProvider.instance.get();
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
|
|
||||||
DiscoveryService discoveryList= new DiscoveryService(context);
|
DiscoveryService discoveryList= new DiscoveryService(context);
|
||||||
List<String> sendersList=sendersList(discoveryList.getBasePath()+NAME_USERNAME_GLOBAL_ROLE,token,discoveryCheck.getRoleNotifier());
|
//List<String> sendersList=sendersList(discoveryList.getBasePath()+NAME_USERNAME_GLOBAL_ROLE,token,discoveryCheck.getRoleNotifier());
|
||||||
configure(identifier, quotaAssigned, quotaUsage, percent);
|
configure(identifier, quotaAssigned, quotaUsage, percent);
|
||||||
|
|
||||||
String text=CleanNotification(discoveryCheck.getTextQuotaAdminExceed());
|
String text=CleanNotification(discoveryCheck.getTextQuotaAdminExceed());
|
||||||
|
@ -128,12 +132,16 @@ public class SendNotification {
|
||||||
|
|
||||||
JSONObject urlParameters = new JSONObject();
|
JSONObject urlParameters = new JSONObject();
|
||||||
List<String> user=new ArrayList<String>();
|
List<String> user=new ArrayList<String>();
|
||||||
identifier="alessandro.pieve";
|
//identifier="alessandro.pieve";
|
||||||
|
|
||||||
|
List<String> sendersList =new ArrayList<String>();
|
||||||
|
sendersList.add("alessandro.pieve");
|
||||||
|
//sendersList.add("scarponi");
|
||||||
for (String cc :sendersList){
|
for (String cc :sendersList){
|
||||||
// user.add(cc);
|
user.add(cc);
|
||||||
}
|
}
|
||||||
user.add(identifier);
|
|
||||||
|
//user.add(identifier);
|
||||||
urlParameters.put("recipients", user);
|
urlParameters.put("recipients", user);
|
||||||
urlParameters.put("body", text);
|
urlParameters.put("body", text);
|
||||||
urlParameters.put("subject", discoveryCheck.getTextQuotaAdminExceedSubject());
|
urlParameters.put("subject", discoveryCheck.getTextQuotaAdminExceedSubject());
|
||||||
|
@ -148,7 +156,7 @@ public class SendNotification {
|
||||||
log.debug("not send notification quota exceed :{}",userExceedQuota.toString());
|
log.debug("not send notification quota exceed :{}",userExceedQuota.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return resultSend;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,19 +166,30 @@ public class SendNotification {
|
||||||
* @return notification with user,quota and percent
|
* @return notification with user,quota and percent
|
||||||
*/
|
*/
|
||||||
private String CleanNotification(String notification){
|
private String CleanNotification(String notification){
|
||||||
|
|
||||||
|
String fullname=DiscoveryListUser.getMapUser(identifier);
|
||||||
|
log.debug("Clean Notification from username:{} to fullname:{}",identifier,fullname);
|
||||||
|
|
||||||
if (notification.contains("{identifier}")){
|
if (notification.contains("{identifier}")){
|
||||||
notification=notification.replace("{identifier}", identifier);
|
notification=notification.replace("{identifier}", fullname);
|
||||||
}
|
}
|
||||||
|
|
||||||
String quotaAssignedLabel;
|
String quotaAssignedLabel;
|
||||||
String quotaUsageLabel;
|
String quotaUsageLabel;
|
||||||
|
String percentLabel;
|
||||||
if (quotaAssigned>1024){
|
if (quotaAssigned>1024){
|
||||||
quotaAssignedLabel=String.valueOf(Math.round((quotaAssigned/1024) * 100.0) / 100.0)+"GB";
|
quotaAssignedLabel=String.valueOf(Math.round((quotaAssigned/1024) * 100.0) / 100.0)+"GB";
|
||||||
quotaUsageLabel= String.valueOf(Math.round((quotaUsage/1024) * 100.0) / 100.0)+"GB";
|
quotaUsageLabel= String.valueOf(Math.round((quotaUsage/1024) * 100.0) / 100.0)+"GB";
|
||||||
|
percentLabel=percent.toString();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
quotaAssignedLabel=String.valueOf(quotaAssigned)+"MB";
|
quotaAssignedLabel=String.valueOf(quotaAssigned)+"MB";
|
||||||
quotaUsageLabel= String.valueOf(quotaUsage)+"MB";
|
quotaUsageLabel= String.valueOf(quotaUsage)+"MB";
|
||||||
|
percentLabel=percent.toString();
|
||||||
|
}
|
||||||
|
if (quotaAssigned==-1){
|
||||||
|
quotaAssignedLabel="∞";
|
||||||
|
percentLabel="0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notification.contains("{quotaAssigned}")){
|
if (notification.contains("{quotaAssigned}")){
|
||||||
|
@ -180,7 +199,7 @@ public class SendNotification {
|
||||||
notification=notification.replace("{quotaUsage}", quotaUsageLabel);
|
notification=notification.replace("{quotaUsage}", quotaUsageLabel);
|
||||||
}
|
}
|
||||||
if (notification.contains("{percent}")){
|
if (notification.contains("{percent}")){
|
||||||
notification=notification.replace("{percent}", percent.toString());
|
notification=notification.replace("{percent}",percentLabel);
|
||||||
}
|
}
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
@ -206,14 +225,13 @@ public class SendNotification {
|
||||||
request.setEntity(params);
|
request.setEntity(params);
|
||||||
HttpResponse response = httpClient.execute(request);
|
HttpResponse response = httpClient.execute(request);
|
||||||
log.debug("writeMsg path:{} urlParameters:{} request:{}",path,urlParameters,request.toString());
|
log.debug("writeMsg path:{} urlParameters:{} request:{}",path,urlParameters,request.toString());
|
||||||
/*
|
|
||||||
log.info("urlParameters:{}",urlParameters.toString());
|
|
||||||
log.info("request:{}",request.toString());
|
|
||||||
*/
|
|
||||||
int status = response.getStatusLine().getStatusCode();
|
int status = response.getStatusLine().getStatusCode();
|
||||||
|
|
||||||
// check the response status and look if it was a redirect problem
|
// check the response status and look if it was a redirect problem
|
||||||
if (status != HttpURLConnection.HTTP_OK && (status == HttpURLConnection.HTTP_MOVED_TEMP ||
|
if ((status ==HttpURLConnection.HTTP_INTERNAL_ERROR)|| (status==HttpURLConnection.HTTP_BAD_GATEWAY)){
|
||||||
|
result=false;
|
||||||
|
}
|
||||||
|
else if (status != HttpURLConnection.HTTP_OK && (status == HttpURLConnection.HTTP_MOVED_TEMP ||
|
||||||
status == HttpURLConnection.HTTP_MOVED_PERM ||
|
status == HttpURLConnection.HTTP_MOVED_PERM ||
|
||||||
status == HttpURLConnection.HTTP_SEE_OTHER)) {
|
status == HttpURLConnection.HTTP_SEE_OTHER)) {
|
||||||
|
|
||||||
|
@ -231,7 +249,8 @@ public class SendNotification {
|
||||||
request.setEntity(params);
|
request.setEntity(params);
|
||||||
response = httpClient.execute(request);
|
response = httpClient.execute(request);
|
||||||
log.info(" " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
|
log.info(" " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
|
||||||
} else{
|
result=true;
|
||||||
|
}else{
|
||||||
log.debug(" " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
|
log.debug(" " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase());
|
||||||
result=true;
|
result=true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue