use of com.emc.storageos.db.client.model.RequestedTokenMap in project coprhd-controller by CoprHD.
the class CassandraTokenManager method cleanUpRequestedTokenMap.
/**
* Removes the RequestedTokenMap associated with the passed in token if it exists.
*
* @param tokenObj
*/
private void cleanUpRequestedTokenMap(Token tokenObj) {
RequestedTokenMap map = tokenMapHelper.getTokenMap(tokenObj.getId().toString());
if (map != null) {
_dbClient.removeObject(map);
_log.info("A token had a stale RequestedTokenMap. Deleting.");
} else {
_log.info("No RequestedTokenMap for token to be deleted.");
}
}
use of com.emc.storageos.db.client.model.RequestedTokenMap in project coprhd-controller by CoprHD.
the class RequestedTokenHelper method getTokenMap.
/**
* Retrieves the list of vdcid that have requested a copy of this token
*
* @param tokenId
* @return
*/
public RequestedTokenMap getTokenMap(String tokenId) {
URIQueryResultList maps = new URIQueryResultList();
List<URI> mapsURI = new ArrayList<URI>();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getRequestedTokenMapTokenIdConstraint(tokenId.toString()), maps);
if (maps == null) {
log.info("No requested token map found. No map.");
return null;
}
while (maps.iterator().hasNext()) {
mapsURI.add(maps.iterator().next());
}
List<RequestedTokenMap> objects = dbClient.queryObject(RequestedTokenMap.class, mapsURI);
if (objects == null || objects.size() != 1) {
log.info("No requested token map found. Empty map.");
return null;
}
return objects.get(0);
}
use of com.emc.storageos.db.client.model.RequestedTokenMap in project coprhd-controller by CoprHD.
the class RequestedTokenHelper method addRequestingVDC.
private void addRequestingVDC(String tokenId, String requestingVDC) {
RequestedTokenMap map = getTokenMap(tokenId);
if (map == null) {
map = new RequestedTokenMap();
map.setId(URIUtil.createId(RequestedTokenMap.class));
map.setTokenID(tokenId);
}
if (!map.getVDCIDs().contains(requestingVDC)) {
map.addVDCID(requestingVDC);
log.debug("Adding shortId {}", requestingVDC);
dbClient.persistObject(map);
}
}
use of com.emc.storageos.db.client.model.RequestedTokenMap in project coprhd-controller by CoprHD.
the class RequestedTokenHelper method removeRequestingVDC.
private void removeRequestingVDC(String tokenId, String requestingVDC) {
RequestedTokenMap map = getTokenMap(tokenId);
if (map != null) {
if (map.getVDCIDs().contains(requestingVDC)) {
map.removeVDCID(requestingVDC);
if (map.getVDCIDs().isEmpty()) {
log.info("Last vdcid entry removed from requested token map. Removing map.");
dbClient.removeObject(map);
} else {
dbClient.persistObject(map);
}
}
}
}
use of com.emc.storageos.db.client.model.RequestedTokenMap in project coprhd-controller by CoprHD.
the class RequestedTokenHelper method notifyExternalVDCs.
/**
* Notify the originatorVDC of the token or follows the map of VDCs that have a copy of this token
* depending on whether or not the passed in token is from this VDC or not.
*
* @param tokenId token URI for lookups in the requested token map
*/
public void notifyExternalVDCs(String rawToken) {
String tokenId = tokenEncoder.decode(rawToken).getTokenId().toString();
// If this is a token this VDC did not create, it needs to call back the
// originator
String originatorVDCId = URIUtil.parseVdcIdFromURI(tokenId);
if (!VdcUtil.getLocalShortVdcId().equals(originatorVDCId)) {
// Call originator. If this fails, this is a problem.
log.info("Calling token originator to propagate deletion of token");
boolean failed = false;
try {
ClientResponse resp = geoClientCacheMgt.getGeoClient(originatorVDCId).logoutToken(rawToken, null, false);
if (resp.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
failed = true;
}
} catch (Exception ex) {
failed = true;
}
if (failed) {
throw RetryableSecurityException.retryables.unableToNotifyTokenOriginatorForLogout(originatorVDCId);
}
}
// Else, if this VDC created this token, go through the list of VDCs
// that may have a copy and notify them.
RequestedTokenMap map = getTokenMap(tokenId);
if (map == null || map.getVDCIDs().isEmpty()) {
return;
}
log.info("This token had potential copies still active in other VDCs. Notifying...");
for (String shortId : map.getVDCIDs()) {
try {
ClientResponse resp = geoClientCacheMgt.getGeoClient(shortId).logoutToken(rawToken, null, false);
// The remove logout notification is a best effort attempt to remove the remote token quicker.
if (resp.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
log.warn("Unable to successfully verify that remote copy of token was deleted. It will expire is less than 10 minutes.");
}
} catch (Exception e) {
log.error("Could not contact remote VDC to invalidate token: {}", shortId);
}
// remove from the requested map whether logout success or not.
removeRequestingVDC(tokenId, shortId);
}
}
Aggregations