Search in sources :

Example 1 with RequestedTokenMap

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.");
    }
}
Also used : RequestedTokenMap(com.emc.storageos.db.client.model.RequestedTokenMap)

Example 2 with RequestedTokenMap

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);
}
Also used : RequestedTokenMap(com.emc.storageos.db.client.model.RequestedTokenMap) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 3 with RequestedTokenMap

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);
    }
}
Also used : RequestedTokenMap(com.emc.storageos.db.client.model.RequestedTokenMap)

Example 4 with RequestedTokenMap

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);
            }
        }
    }
}
Also used : RequestedTokenMap(com.emc.storageos.db.client.model.RequestedTokenMap)

Example 5 with RequestedTokenMap

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);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RequestedTokenMap(com.emc.storageos.db.client.model.RequestedTokenMap) RetryableSecurityException(com.emc.storageos.security.exceptions.RetryableSecurityException) SecurityException(com.emc.storageos.security.exceptions.SecurityException)

Aggregations

RequestedTokenMap (com.emc.storageos.db.client.model.RequestedTokenMap)7 Test (org.junit.Test)2 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)1 DbClient (com.emc.storageos.db.client.DbClient)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 BaseToken (com.emc.storageos.db.client.model.BaseToken)1 ProxyToken (com.emc.storageos.db.client.model.ProxyToken)1 StorageOSUserDAO (com.emc.storageos.db.client.model.StorageOSUserDAO)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 Token (com.emc.storageos.db.client.model.Token)1 SignedToken (com.emc.storageos.security.authentication.Base64TokenEncoder.SignedToken)1 TokenOnWire (com.emc.storageos.security.authentication.TokenOnWire)1 RetryableSecurityException (com.emc.storageos.security.exceptions.RetryableSecurityException)1 SecurityException (com.emc.storageos.security.exceptions.SecurityException)1 RequestedTokenHelper (com.emc.storageos.security.geo.RequestedTokenHelper)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1