Skip to content

Commit

Permalink
Refactored notificatio mechanism for account removal
Browse files Browse the repository at this point in the history
- A simple request with variable number of notifications is submitted.
- Both restcomm and RVD are updated.
- Adapted arquilian and other test cases.
- Added timeout conf parameter for rcmlserver api.

Refers #1270
  • Loading branch information
otsakir committed Oct 14, 2016
1 parent 3acd55a commit b63e75c
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ private CustomHttpClientBuilder() {
}

public static HttpClient build(MainConfigurationSet config) {
SslMode mode = config.getSslMode();
int timeoutConnection = config.getResponseTimeout();
return build(config, timeoutConnection);
}

public static HttpClient build(MainConfigurationSet config, int timeout) {
SslMode mode = config.getSslMode();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(timeoutConnection)
.setConnectionRequestTimeout(timeoutConnection)
.setSocketTimeout(timeoutConnection)
.setConnectTimeout(timeout)
.setConnectionRequestTimeout(timeout)
.setSocketTimeout(timeout)
.setCookieSpec(CookieSpecs.STANDARD).build();
if ( mode == SslMode.strict ) {
return HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
public interface RcmlserverConfigurationSet {
String getBaseUrl();
Boolean getNotify();
Integer getTimeout(); // how much to wait for response to a notification request before giving up
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
public class RcmlserverConfigurationSetImpl extends ConfigurationSet implements RcmlserverConfigurationSet {
private static final String BASE_URL_KEY = "rcmlserver-api.base-url";
private static final String NOTIFY_KEY = "rcmlserver-api.notifications";
private static final String TIMEOUT_KEY = "rcmlserver-api.timeout";
private String baseUrl = null;
private Boolean notify = false;
private Integer timeout = 5000;

public RcmlserverConfigurationSetImpl(ConfigurationSource source) {
super(source);
Expand Down Expand Up @@ -67,4 +69,10 @@ public String getBaseUrl() {
public Boolean getNotify() {
return notify;
}

@Override
public Integer getTimeout() {
return this.timeout;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@
import org.restcomm.connect.dao.entities.Client;
import org.restcomm.connect.dao.entities.RestCommResponse;
import org.restcomm.connect.commons.dao.Sid;
import org.restcomm.connect.http.client.rcmlserver.RcmlserverNotifications;
import org.restcomm.connect.http.converter.AccountConverter;
import org.restcomm.connect.http.converter.AccountListConverter;
import org.restcomm.connect.http.converter.RestCommResponseConverter;
import org.restcomm.connect.http.exceptions.AuthorizationException;
import org.restcomm.connect.http.exceptions.InsufficientPermission;
import org.restcomm.connect.http.exceptions.AccountAlreadyClosed;
import org.restcomm.connect.commons.util.StringUtils;
import org.restcomm.connect.http.client.RcmlserverApi;
import org.restcomm.connect.http.client.rcmlserver.RcmlserverApi;
import org.restcomm.connect.http.exceptions.RcmlserverNotifyError;

/**
* @author quintana.thomas@gmail.com (Thomas Quintana)
Expand Down Expand Up @@ -467,15 +469,18 @@ protected Response updateAccount(final String identifier, final MultivaluedMap<S
}

/**
* Removes all resources belonging to an account and sets its status to CLOSED.
* Removes all resources belonging to an account and sets its status to CLOSED. If skipStatusUpdate is true, it will only
* remove resources and not update the status to CLOSED.
*
* @param closedAccount
*/
private void closeSingleAccount(Account closedAccount) {
private void closeSingleAccount(Account closedAccount, boolean skipStatusUpdate) {
removeAccoundDependencies(closedAccount.getSid());
// finally, set account status to closed.
closedAccount = closedAccount.setStatus(Account.Status.CLOSED);
accountsDao.updateAccount(closedAccount);
if (!skipStatusUpdate) {
closedAccount = closedAccount.setStatus(Account.Status.CLOSED);
accountsDao.updateAccount(closedAccount);
}
}

/**
Expand All @@ -485,9 +490,17 @@ private void closeSingleAccount(Account closedAccount) {
* @param parentAccount
*/
private void closeAccountTree(Account parentAccount) {
// do we need to also notify the application sever (RVD) ?
RestcommConfiguration rcommConfiguration = RestcommConfiguration.getInstance();
RcmlserverConfigurationSet config = rcommConfiguration.getRcmlserver();
RcmlserverApi rcmlserverApi = null;
RcmlserverNotifications notifications = new RcmlserverNotifications();
if (config != null && config.getNotify()) {
// create an RcmlserverApi object only if we will need to notify
rcmlserverApi = new RcmlserverApi(rcommConfiguration.getMain(), rcommConfiguration.getRcmlserver());
}
// close child accounts
List<String> subAccountsToClose = accountsDao.getSubAccountSidsRecursive(parentAccount.getSid());
List<String> closedSubAccounts = new ArrayList<String>();
if (subAccountsToClose != null && !subAccountsToClose.isEmpty()) {
int i = subAccountsToClose.size(); // is is the count of accounts left to process
// we iterate backwards to handle child accounts first, parent accounts next
Expand All @@ -496,27 +509,29 @@ private void closeAccountTree(Account parentAccount) {
String removedSid = subAccountsToClose.get(i);
try {
Account subAccount = accountsDao.getAccount(new Sid(removedSid));
closeSingleAccount(subAccount);
closedSubAccounts.add(subAccount.getSid().toString());
closeSingleAccount(subAccount,false);
notifications.add(rcmlserverApi.buildAccountClosingNotification(subAccount));
} catch (Exception e) {
// if anything bad happens, log the error and continue removing the rest of the accounts.
logger.error("Failed removing (child) account '" + removedSid + "'");
closedSubAccounts.add(removedSid.toString()); // we choose to remove remove projects for this account. TODO review this bahavior
}
}
}
// close parent account too
closeSingleAccount(parentAccount);
closedSubAccounts.add(parentAccount.getSid().toString());
// do we need to also notify the application sever (RVD) ?
RestcommConfiguration rcommConfiguration = RestcommConfiguration.getInstance();
RcmlserverConfigurationSet config = rcommConfiguration.getRcmlserver();
if (config != null && config.getNotify()) {
// create an RcmlserverApi object only if we will need to notify
RcmlserverApi api = new RcmlserverApi(rcommConfiguration.getMain(), rcommConfiguration.getRcmlserver());

// close parent account too. Skip status update. We need to send notifications first.
closeSingleAccount(parentAccount,true);
notifications.add(rcmlserverApi.buildAccountClosingNotification(parentAccount));
if (rcmlserverApi != null) {
Account loggedAccount = userIdentityContext.getEffectiveAccount();
api.notifyAccountsRemovalAsync(closedSubAccounts, loggedAccount.getSid().toString(), loggedAccount.getAuthToken() );
try {
rcmlserverApi.transmitNotifications(notifications, loggedAccount.getSid().toString(), loggedAccount.getAuthToken() );
} catch (RcmlserverNotifyError e) {
logger.error(e.getMessage(),e); // just report
}
}
parentAccount = parentAccount.setStatus(Account.Status.CLOSED);
accountsDao.updateAccount(parentAccount);

}

private void validate(final MultivaluedMap<String, String> data) throws NullPointerException {
Expand Down

This file was deleted.

Loading

0 comments on commit b63e75c

Please sign in to comment.