Search in sources :

Example 1 with InvalidSession

use of com.vmware.vim.vasa._1_0.InvalidSession in project coprhd-controller by CoprHD.

the class ContextManagerImpl method getUsageContext.

/**
 * called by vasaService APIs to verify the connection and get the
 * UsageContext.
 */
public UsageContext getUsageContext() throws InvalidSession, StorageFault {
    final String methodName = "getUsageContext(): ";
    log.debug(methodName + "Entry");
    try {
        // verify valid SSL and VASA Sessions.
        String sessionId = _sslUtil.getCookie(SSLUtil.VASA_SESSIONID_STR);
        if (sessionId == null) {
            // throw an exception
            throw FaultUtil.StorageFault("getUsageContext internal error.");
        }
        log.trace(methodName + "Looking for sessin context by session id...");
        SessionContext sc = SessionContext.lookupSessionContextBySessionId(sessionId);
        if (sc == null) {
            // throw an exception
            throw FaultUtil.StorageFault("getUsageContext internal error.");
        }
        _sslUtil.setHttpResponse(sc);
        UsageContext uc = sc.getUsageContext();
        if (uc == null) {
            throw FaultUtil.StorageFault("UsageContext is not set");
        }
        // validateUsageContext(uc);
        return uc;
    } catch (StorageFault sf) {
        // thrown by this function
        log.error(methodName + "storage fault occured", sf);
        throw sf;
    } catch (InvalidSession is) {
        log.error(methodName + "invalid session", is);
        throw is;
    } catch (Exception e) {
        log.error(methodName + "unexpected error", e);
        throw FaultUtil.InvalidSession("runtime", e);
    }
}
Also used : UsageContext(com.vmware.vim.vasa._1_0.data.xsd.UsageContext) StorageFault(com.vmware.vim.vasa._1_0.StorageFault) SessionContext(com.emc.storageos.vasa.util.SessionContext) InvalidSession(com.vmware.vim.vasa._1_0.InvalidSession) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateExpiredException(java.security.cert.CertificateExpiredException)

Example 2 with InvalidSession

use of com.vmware.vim.vasa._1_0.InvalidSession in project coprhd-controller by CoprHD.

the class ContextManagerImpl method getSOSManager.

public SOSManager getSOSManager() throws StorageFault, InvalidSession {
    final String methodName = "getSOSManager(): ";
    log.debug(methodName + "Entry");
    try {
        // verify valid SSL and VASA Sessions.
        String sessionId = _sslUtil.getCookie(SSLUtil.VASA_SESSIONID_STR);
        if (sessionId == null) {
            // throw an exception
            throw FaultUtil.StorageFault(methodName + "internal error");
        }
        log.trace(methodName + "Looking for session context by session id...");
        SessionContext sc = SessionContext.lookupSessionContextBySessionId(sessionId);
        if (sc == null) {
            // throw an exception
            throw FaultUtil.StorageFault("getUsageContext internal error.");
        }
        _sslUtil.setHttpResponse(sc);
        SOSManager sosManager = sc.getSosManager();
        if (sosManager == null) {
            throw FaultUtil.StorageFault("SOSManager is not set");
        }
        // validateUsageContext(uc);
        return sosManager;
    } catch (StorageFault sf) {
        // thrown by this function
        log.error(methodName + "storage fault occured", sf);
        throw sf;
    } catch (InvalidSession is) {
        log.error(methodName + "invalid session", is);
        throw is;
    } catch (Exception e) {
        log.error(methodName + "unexpected error", e);
        throw FaultUtil.InvalidSession("runtime", e);
    }
}
Also used : StorageFault(com.vmware.vim.vasa._1_0.StorageFault) SessionContext(com.emc.storageos.vasa.util.SessionContext) InvalidSession(com.vmware.vim.vasa._1_0.InvalidSession) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateExpiredException(java.security.cert.CertificateExpiredException)

Example 3 with InvalidSession

use of com.vmware.vim.vasa._1_0.InvalidSession in project coprhd-controller by CoprHD.

the class ContextManagerImpl method setContext.

/**
 * vasaService interface
 */
@Override
public VasaProviderInfo setContext(UsageContext uc) throws InvalidArgument, InvalidSession, StorageFault {
    final String methodName = "setContext(): ";
    log.debug(methodName + "Entry");
    if (log.isDebugEnabled()) {
        HostInitiatorInfo[] hostInitiators = uc.getHostInitiator();
        if (hostInitiators != null && hostInitiators.length > 0) {
            log.debug(methodName + "list of host initiators (HBA):");
            for (HostInitiatorInfo initiator : hostInitiators) {
                log.debug(methodName + "id[" + initiator.getUniqueIdentifier() + "] iSCSIId[" + initiator.getIscsiIdentifier() + "] nodeWWN[" + initiator.getNodeWwn() + "] portWWN[" + initiator.getPortWwn() + "]");
            }
        }
        String[] iscsiIpAddresseses = uc.getIscsiInitiatorIpAddress();
        if (iscsiIpAddresseses != null) {
            log.debug(methodName + "list of iSCSI initiator IP addresses:");
            log.debug(methodName + Arrays.asList(iscsiIpAddresseses));
        }
        MountInfo[] mountPoints = uc.getMountPoint();
        if (mountPoints != null && mountPoints.length > 0) {
            log.debug(methodName + "List of file share mount paths:");
            for (MountInfo mountPoint : mountPoints) {
                log.debug(methodName + "filePath[" + mountPoint.getFilePath() + "] serverName[" + mountPoint.getServerName() + "]");
            }
        }
        log.debug(methodName + "vSphere service instance Id[" + uc.getVcGuid() + "]");
    }
    String clientAddress = "unknown";
    try {
        // _sslUtil.checkForUniqueVASASessionId();
        SessionContext sc = null;
        clientAddress = _sslUtil.checkHttpRequest(true, false);
        // Tear down any existing session
        log.debug(methodName + "Tear down any existing session");
        invalidateSession();
        // Create new session.
        sc = SessionContext.createSession(uc, clientAddress);
        log.trace(methodName + "Created a new session: " + sc.getSessionId());
        sc.setSosManager(_sosManager);
        log.trace(methodName + "SOS manager is set in session context: " + sc.getSessionId());
        _vpInfo.setSessionId(sc.getSessionId());
        _sslUtil.setHttpResponse(sc);
        log.debug(methodName + "Exit returning VasaProviderInfo with new session Id[" + _vpInfo.getSessionId() + "]");
        return _vpInfo;
    } catch (StorageFault sf) {
        log.error(methodName + " unknown exception occured", sf);
        throw sf;
    } catch (InvalidSession is) {
        log.error(methodName + "Invalid session exception", is);
        throw is;
    } catch (Exception e) {
        log.error("unknown exception occured", e);
        throw FaultUtil.StorageFault("runtime ", e);
    }
}
Also used : HostInitiatorInfo(com.vmware.vim.vasa._1_0.data.xsd.HostInitiatorInfo) StorageFault(com.vmware.vim.vasa._1_0.StorageFault) SessionContext(com.emc.storageos.vasa.util.SessionContext) MountInfo(com.vmware.vim.vasa._1_0.data.xsd.MountInfo) InvalidSession(com.vmware.vim.vasa._1_0.InvalidSession) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateExpiredException(java.security.cert.CertificateExpiredException)

Example 4 with InvalidSession

use of com.vmware.vim.vasa._1_0.InvalidSession in project coprhd-controller by CoprHD.

the class ContextManagerImpl method registerVASACertificate.

/**
 * vasaService interface
 */
@Override
public VasaProviderInfo registerVASACertificate(String username, String password, String certificateStr) throws InvalidCertificate, InvalidLogin, InvalidSession, StorageFault {
    final String methodName = "registerVASACertificate() :";
    log.debug(methodName + "Entry with inputs username[" + username + "] password[" + (password != null ? "****" : null) + "] certificateStr[" + (certificateStr != null ? "****" : null) + "]");
    try {
        _sosManager = new SOSManager();
        /*
             * Verify username/password before verifying certificate. This means
             * that if both username/password and certificate are invalid
             * InvalidLogin exception will be thrown.
             */
        _sosManager.verifyLoginCredentials(username, password);
        log.debug(methodName + "Valid username and password. User credentials accepted.");
        String clientAddress = _sslUtil.checkHttpRequest(false, false);
        X509Certificate x509Cert = (X509Certificate) _sslUtil.buildCertificate(certificateStr);
        x509Cert.checkValidity();
        if (!_sslUtil.certificateIsTrusted((Certificate) x509Cert)) {
            _sslUtil.addCertificateToTrustStore(clientAddress, (Certificate) x509Cert);
            log.trace(methodName + "new certificate added as trusted");
            _sslUtil.refreshTrustStore();
            invalidateSession();
        } else {
            log.trace(methodName + "certificate was already trusted");
        }
        log.trace(methodName + "vpInfo: defaultNameSpace[" + _vpInfo.getDefaultNamespace() + "] name[" + _vpInfo.getName() + "] sessionId[" + _vpInfo.getSessionId() + " vasaApiVersion[" + _vpInfo.getVasaApiVersion() + "] vasaProviderVersion[" + _vpInfo.getVasaProviderVersion() + "]");
        log.debug(methodName + "Exit returning vpInfo");
        return _vpInfo;
    } catch (InvalidSession is) {
        // thrown by sslUtil.checkHttpRequest()
        log.error(methodName + "Session is invalid", is);
        throw is;
    } catch (InvalidCertificate ic) {
        // thrown by sslUtil.buildCertificate()
        log.error(methodName + "Certificate is invalid", ic);
        throw ic;
    } catch (CertificateExpiredException e) {
        // thrown by x509Cert.checkValidity()
        log.error(methodName + "Certificate is expired", e);
        throw FaultUtil.InvalidCertificate(e);
    } catch (CertificateNotYetValidException e) {
        // thrown by x509Cert.checkValidity()
        log.error(methodName + "Certificate is not in validity period ", e);
        throw FaultUtil.InvalidCertificate(e);
    } catch (InvalidLogin il) {
        // thrown by verifyPassword();
        log.error(methodName + "Invalid login", il);
        throw il;
    } catch (Exception e) {
        log.error(methodName + "registration failed: ", e);
        throw FaultUtil.StorageFault(methodName + "registration failed: ", e);
    }
}
Also used : InvalidCertificate(com.vmware.vim.vasa._1_0.InvalidCertificate) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateExpiredException(java.security.cert.CertificateExpiredException) InvalidLogin(com.vmware.vim.vasa._1_0.InvalidLogin) X509Certificate(java.security.cert.X509Certificate) InvalidSession(com.vmware.vim.vasa._1_0.InvalidSession) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateExpiredException(java.security.cert.CertificateExpiredException) X509Certificate(java.security.cert.X509Certificate) InvalidCertificate(com.vmware.vim.vasa._1_0.InvalidCertificate) Certificate(java.security.cert.Certificate)

Example 5 with InvalidSession

use of com.vmware.vim.vasa._1_0.InvalidSession in project coprhd-controller by CoprHD.

the class SOSManager method queryDRSMigrationCapabilityForPerformance.

public synchronized boolean queryDRSMigrationCapabilityForPerformance(String srcUniqueId, String dstUniqueId, String entityType) throws InvalidArgument, NotFound, InvalidSession, StorageFault {
    final String methodName = "queryDRSMigrationCapabilityForPerformance(): ";
    log.debug(methodName + "Entry with input(s) srcUniqueId[" + srcUniqueId + "] dstUniqueId[" + dstUniqueId + "] entityType[" + entityType + "]");
    try {
        if (Util.isEmpty(entityType)) {
            throw FaultUtil.InvalidArgument("Given entity type is invalid: [" + entityType + "]");
        }
        List<String> validEntityTypeList = new ArrayList<String>();
        validEntityTypeList.add(EntityTypeEnum.StorageFileSystem.getValue());
        validEntityTypeList.add(EntityTypeEnum.StorageLun.getValue());
        if (validEntityTypeList.contains(entityType) == false) {
            throw FaultUtil.InvalidArgument("Given entity type is invalid: [" + entityType + "]");
        }
        if (Util.isEmpty(srcUniqueId) || Util.isEmpty(dstUniqueId)) {
            throw FaultUtil.InvalidArgument("Given identifiers are invalid");
        }
        Boolean supportsFile = new Boolean(_config.getConfigValue("config/service/storageTopology/storageArray/support-file-profile"));
        if (EntityTypeEnum.StorageFileSystem.getValue().equals(entityType)) {
            if (!supportsFile) {
                throw FaultUtil.InvalidArgument("Given entity type is invalid: [" + entityType + "]. It does not match with the supported array profile");
            }
            if (!srcUniqueId.startsWith(FILESYSTEM_IDENTIFIER_PREFIX) || !dstUniqueId.startsWith(FILESYSTEM_IDENTIFIER_PREFIX)) {
                throw FaultUtil.InvalidArgument("Given identifiers are invalid");
            }
        }
        Boolean supportsBlock = new Boolean(_config.getConfigValue("config/service/storageTopology/storageArray/support-block-profile"));
        if (EntityTypeEnum.StorageLun.getValue().equals(entityType)) {
            if (!supportsBlock) {
                throw FaultUtil.InvalidArgument("Given entity type is invalid: [" + entityType + "]. It does not match with the supported array profile");
            }
            if (!srcUniqueId.startsWith(VOLUME_IDENTIFIER_PREFIX) || !dstUniqueId.startsWith(VOLUME_IDENTIFIER_PREFIX)) {
                throw FaultUtil.InvalidArgument("Given identifiers are invalid");
            }
        }
        List<String> inputIdList = new ArrayList<String>();
        inputIdList.add(srcUniqueId);
        inputIdList.add(dstUniqueId);
        if (EntityTypeEnum.StorageFileSystem.getValue().equals(entityType)) {
            this.setFileSystemIds();
            if (srcUniqueId.startsWith(FILESYSTEM_IDENTIFIER_PREFIX) && dstUniqueId.startsWith(VOLUME_IDENTIFIER_PREFIX)) {
                return false;
            } else {
                if (!_reportedFileSystemIdList.contains(srcUniqueId)) {
                    log.error(methodName + "Source Id does not exist for the entity type[" + entityType + "]");
                    throw FaultUtil.NotFound("Source Id does not exist for the entity type[" + entityType + "]");
                }
                if (!_reportedFileSystemIdList.contains(dstUniqueId)) {
                    log.error(methodName + "Destination Id does not exist for the entity type[" + entityType + "]");
                    throw FaultUtil.NotFound("Destination Id does not exist for the entity type[" + entityType + "]");
                }
            }
            List<FileShare> fileShareList = _syncManager.getFileSystemDetailList(inputIdList);
            FileShare fileShare1 = fileShareList.get(0);
            FileShare fileShare2 = fileShareList.get(1);
            if (fileShare1.getPool() != null && fileShare2.getPool() != null && fileShare1.getPool().getId() != null && fileShare2.getPool().getId() != null) {
                if (fileShare1.getPool().getId().equals(fileShare2.getPool().getId())) {
                    return false;
                } else {
                    return true;
                }
            }
        }
        if (EntityTypeEnum.StorageLun.getValue().equals(entityType)) {
            this.setVolumeIds();
            if (srcUniqueId.startsWith(FILESYSTEM_IDENTIFIER_PREFIX) && dstUniqueId.startsWith(VOLUME_IDENTIFIER_PREFIX)) {
                return false;
            } else {
                if (!_reportedVolumeIdList.contains(srcUniqueId)) {
                    log.error(methodName + "Source  Id does not exist for the entity type[" + entityType + "]");
                    throw FaultUtil.NotFound("Source Id does not exist for the entity type[" + entityType + "]");
                }
                if (!_reportedVolumeIdList.contains(dstUniqueId)) {
                    log.error(methodName + "Destination  Id does not exist for the entity type[" + entityType + "]");
                    throw FaultUtil.NotFound("Destination Id does not exist for the entity type[" + entityType + "]");
                }
            }
            // Check if src and dest are VPLEX volumes
            List<Volume> volumeDetailList = _syncManager.getVolumeDetailList(inputIdList);
            for (Volume volume : volumeDetailList) {
                if (volume != null) {
                    HighAvailabilityVolumes haVolumes = volume.getHaVolumeList();
                    if (haVolumes != null && haVolumes.getHaVolumeList() != null) {
                        return false;
                    }
                }
            }
            // Regular volumes
            AssociatedPool associatedPoolForVolume1 = _syncManager.fetchAssociatedPoolOfVolume(srcUniqueId);
            AssociatedPool associatedPoolForVolume2 = _syncManager.fetchAssociatedPoolOfVolume(dstUniqueId);
            if (associatedPoolForVolume1 != null && associatedPoolForVolume2 != null) {
                if (associatedPoolForVolume1.getStoragepool().getId().equals(associatedPoolForVolume2.getStoragepool().getId())) {
                    return false;
                } else {
                    return true;
                }
            }
        }
    } catch (SOSFailure e) {
        log.error("StorageOSFailure occured", e);
        throw FaultUtil.StorageFault("StorageOSFailure occured", e);
    } catch (InvalidArgument e) {
        log.error(methodName + "InvalidArgument occured ", e);
        throw e;
    } catch (NotFound e) {
        log.error(methodName + "NotFound occured ", e);
        throw e;
    }
    return false;
}
Also used : HighAvailabilityVolumes(com.emc.storageos.vasa.data.internal.Volume.HighAvailabilityVolumes) AssociatedPool(com.emc.storageos.vasa.data.internal.Volume.AssociatedPool) ArrayList(java.util.ArrayList) FileShare(com.emc.storageos.vasa.data.internal.FileShare) Volume(com.emc.storageos.vasa.data.internal.Volume) InvalidArgument(com.vmware.vim.vasa._1_0.InvalidArgument) SOSFailure(com.emc.storageos.vasa.fault.SOSFailure) NotFound(com.vmware.vim.vasa._1_0.NotFound)

Aggregations

InvalidArgument (com.vmware.vim.vasa._1_0.InvalidArgument)13 NotImplemented (com.vmware.vim.vasa._1_0.NotImplemented)10 ArrayList (java.util.ArrayList)10 SOSFailure (com.emc.storageos.vasa.fault.SOSFailure)8 StorageFault (com.vmware.vim.vasa._1_0.StorageFault)8 InvalidSession (com.vmware.vim.vasa._1_0.InvalidSession)7 CertificateExpiredException (java.security.cert.CertificateExpiredException)7 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)7 UsageContext (com.vmware.vim.vasa._1_0.data.xsd.UsageContext)6 BaseStorageEntity (com.vmware.vim.vasa._1_0.data.xsd.BaseStorageEntity)5 VasaAssociationObject (com.vmware.vim.vasa._1_0.data.xsd.VasaAssociationObject)5 FileShare (com.emc.storageos.vasa.data.internal.FileShare)3 Volume (com.emc.storageos.vasa.data.internal.Volume)3 SessionContext (com.emc.storageos.vasa.util.SessionContext)3 InvalidCertificate (com.vmware.vim.vasa._1_0.InvalidCertificate)3 HostInitiatorInfo (com.vmware.vim.vasa._1_0.data.xsd.HostInitiatorInfo)3 EventList (com.emc.storageos.vasa.data.internal.Event.EventList)2 MountInfo (com.vmware.vim.vasa._1_0.data.xsd.MountInfo)2 StorageArray (com.vmware.vim.vasa._1_0.data.xsd.StorageArray)2 VasaProviderInfo (com.vmware.vim.vasa._1_0.data.xsd.VasaProviderInfo)2