Search in sources :

Example 1 with HP3PARApi

use of com.emc.storageos.hp3par.impl.HP3PARApi in project coprhd-controller by CoprHD.

the class HP3PARUtil method getHP3PARDeviceFromNativeId.

public HP3PARApi getHP3PARDeviceFromNativeId(String nativeId, Registry driverRegistry) throws HP3PARException {
    try {
        Map<String, List<String>> connectionInfo = driverRegistry.getDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, nativeId);
        List<String> ipAddress = connectionInfo.get(HP3PARConstants.IP_ADDRESS);
        List<String> portNumber = connectionInfo.get(HP3PARConstants.PORT_NUMBER);
        List<String> userName = connectionInfo.get(HP3PARConstants.USER_NAME);
        List<String> password = connectionInfo.get(HP3PARConstants.PASSWORD);
        HP3PARApi hp3parApi = getHP3PARDevice(ipAddress.get(0), portNumber.get(0), userName.get(0), password.get(0));
        return hp3parApi;
    } catch (Exception e) {
        e.printStackTrace();
        _log.error("3PARDriver:Error in getting 3PAR device with nativeId");
        throw new HP3PARException("Error in getting 3PAR device");
    }
}
Also used : HP3PARException(com.emc.storageos.hp3par.impl.HP3PARException) List(java.util.List) HP3PARApi(com.emc.storageos.hp3par.impl.HP3PARApi) HP3PARException(com.emc.storageos.hp3par.impl.HP3PARException)

Example 2 with HP3PARApi

use of com.emc.storageos.hp3par.impl.HP3PARApi in project coprhd-controller by CoprHD.

the class HP3PARUtil method discoverStoragePortsById.

/**
 * Get storage port information
 * @throws Exception
 */
public void discoverStoragePortsById(String storageSystemId, List<StoragePort> storagePorts, Registry driverRegistery) throws Exception {
    // For this 3PAR system
    try {
        // get Api client
        HP3PARApi hp3parApi = getHP3PARDeviceFromNativeId(storageSystemId, driverRegistery);
        // get storage port details
        PortCommandResult portResult = hp3parApi.getPortDetails();
        PortStatisticsCommandResult portStatResult = hp3parApi.getPortStatisticsDetail();
        // for each ViPR Storage port = 3PAR host port
        for (PortMembers currMember : portResult.getMembers()) {
            StoragePort port = new StoragePort();
            // Consider online target ports
            if (currMember.getMode() != HP3PARConstants.MODE_TARGET || currMember.getLinkState() != HP3PARConstants.LINK_READY) {
                continue;
            }
            if (currMember.getLabel() == null) {
                String label = String.format("port:%s:%s:%s", currMember.getPortPos().getNode(), currMember.getPortPos().getSlot(), currMember.getPortPos().getCardPort());
                port.setPortName(label);
            } else {
                port.setPortName(currMember.getLabel());
            }
            port.setStorageSystemId(storageSystemId);
            switch(currMember.getProtocol()) {
                case 1:
                    port.setTransportType(TransportType.FC);
                    break;
                case 3:
                    port.setTransportType(TransportType.Ethernet);
                    break;
                case 2:
                    port.setTransportType(TransportType.IP);
                    break;
                default:
                    _log.warn("3PARDriver: discoverStoragePorts Invalid port {}", port.getPortName());
                    break;
            }
            for (PortStatMembers currStat : portStatResult.getMembers()) {
                if (currMember.getPortPos().getNode() == currStat.getNode() && currMember.getPortPos().getSlot() == currStat.getSlot() && currMember.getPortPos().getCardPort() == currStat.getCardPort()) {
                    port.setPortSpeed(currStat.getSpeed() * HP3PARConstants.MEGA_BYTE);
                }
            }
            // grouping with cluster node and slot
            port.setPortGroup(currMember.getPortPos().getNode().toString());
            port.setPortSubGroup(currMember.getPortPos().getSlot().toString());
            // set specific properties based on protocol
            if (port.getTransportType().equals(TransportType.FC.toString())) {
                port.setPortNetworkId(SanUtils.formatWWN(currMember.getPortWWN()));
                // rest of the values
                port.setEndPointID(port.getPortNetworkId());
                port.setTcpPortNumber((long) 0);
            } else if (port.getTransportType().equals(TransportType.IP.toString())) {
                port.setIpAddress(currMember.getIPAddr());
                port.setPortNetworkId(currMember.getiSCSINmae());
                port.setTcpPortNumber(currMember.getiSCSIPortInfo().getiSNSPort());
                // rest of the values
                port.setEndPointID(port.getPortNetworkId());
            }
            port.setAvgBandwidth(port.getPortSpeed());
            port.setPortHAZone(String.format("Group-%s", currMember.getPortPos().getNode()));
            String id = String.format("%s:%s:%s", currMember.getPortPos().getNode(), currMember.getPortPos().getSlot(), currMember.getPortPos().getCardPort());
            // Storage object properties
            port.setNativeId(id);
            port.setDeviceLabel(port.getPortName());
            port.setDisplayName(port.getPortName());
            port.setOperationalStatus(StoragePort.OperationalStatus.OK);
            _log.info("3PARDriver: added storage port {}, native id {}", port.getPortName(), port.getNativeId());
            storagePorts.add(port);
        }
    // for each storage pool
    } catch (Exception e) {
        throw e;
    }
}
Also used : PortMembers(com.emc.storageos.hp3par.command.PortMembers) PortCommandResult(com.emc.storageos.hp3par.command.PortCommandResult) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) PortStatMembers(com.emc.storageos.hp3par.command.PortStatMembers) HP3PARApi(com.emc.storageos.hp3par.impl.HP3PARApi) PortStatisticsCommandResult(com.emc.storageos.hp3par.command.PortStatisticsCommandResult) HP3PARException(com.emc.storageos.hp3par.impl.HP3PARException)

Example 3 with HP3PARApi

use of com.emc.storageos.hp3par.impl.HP3PARApi in project coprhd-controller by CoprHD.

the class HP3PARApiFactory method main.

// Sample direct program
public static void main(String[] args) {
    System.out.println("starting HP3PAR main");
    try {
        URI uri = URI.create(String.format("https://xxxxx:8080/api/v1/credentials"));
        HP3PARApiFactory factory = new HP3PARApiFactory();
        factory.setConnectionTimeoutMs(30000 * 4);
        factory.setConnManagerTimeout(60000 * 4);
        factory.setSocketConnectionTimeoutMs(7200000 * 4);
        BasicConfigurator.configure();
        factory.init();
        HP3PARApi hp3parApi = factory.getRESTClient(uri, "xxx", "xxxx");
        String authToken = hp3parApi.getAuthToken("xxxx", "xxxx");
        System.out.println(authToken);
        hp3parApi.verifyUserRole("test2");
        SystemCommandResult sysRes = hp3parApi.getSystemDetails();
        System.out.println(sysRes.toString());
        CPGCommandResult cpgRes = hp3parApi.getAllCPGDetails();
        System.out.println(cpgRes.toString());
        hp3parApi.getPortDetails();
        PortStatisticsCommandResult portStatRes = hp3parApi.getPortStatisticsDetail();
        HostSetDetailsCommandResult hostsetRes = hp3parApi.getHostSetDetails("Cluster2021");
        boolean present = false;
        for (int index = 0; index < hostsetRes.getSetmembers().size(); index++) {
            if ("myhost1".compareTo(hostsetRes.getSetmembers().get(index)) == 0) {
                present = true;
                break;
            }
        }
        if (present == false) {
            // update cluster with this host
            hp3parApi.updateHostSet("Cluster2021", "host1");
        }
    } catch (Exception e) {
        System.out.println("EROR");
        System.out.println(e);
        System.out.println(CompleteError.getStackTrace(e));
        e.printStackTrace();
    }
}
Also used : HostSetDetailsCommandResult(com.emc.storageos.hp3par.command.HostSetDetailsCommandResult) CPGCommandResult(com.emc.storageos.hp3par.command.CPGCommandResult) SystemCommandResult(com.emc.storageos.hp3par.command.SystemCommandResult) HP3PARApi(com.emc.storageos.hp3par.impl.HP3PARApi) URI(java.net.URI) PortStatisticsCommandResult(com.emc.storageos.hp3par.command.PortStatisticsCommandResult) HP3PARException(com.emc.storageos.hp3par.impl.HP3PARException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 4 with HP3PARApi

use of com.emc.storageos.hp3par.impl.HP3PARApi in project coprhd-controller by CoprHD.

the class HP3PARApiFactory method getRESTClient.

/**
 * Create HP3PAR API client
 *
 * @param endpoint
 * @param username
 * @param password
 * @return api client
 * @throws HP3PARException
 */
public HP3PARApi getRESTClient(URI endpoint, String username, String password) throws HP3PARException {
    try {
        _log.info("3PARDriver:getRESTClient");
        // key=uri+user+pass to make unique, value=HP3PARApi object
        HP3PARApi hp3parApi = _clientMap.get(endpoint.toString() + ":" + username + ":" + password);
        if (hp3parApi == null) {
            _log.info("3PARDriver:getRESTClient1 hp3parApi null");
            ClientHandler handler = new URLConnectionClientHandler();
            Client connClient = new Client(handler, configureClient());
            RESTClient restClient = new RESTClient(connClient);
            hp3parApi = new HP3PARApi(endpoint, restClient, username, password);
            _clientMap.putIfAbsent(endpoint.toString() + ":" + username + ":" + password, hp3parApi);
        }
        return hp3parApi;
    } catch (Exception e) {
        e.printStackTrace();
        _log.error("3PARDriver:getRESTClient Error in getting RESTclient");
        throw new HP3PARException(e.toString());
    }
}
Also used : HP3PARException(com.emc.storageos.hp3par.impl.HP3PARException) ClientHandler(com.sun.jersey.api.client.ClientHandler) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) ApacheHttpClientHandler(com.sun.jersey.client.apache.ApacheHttpClientHandler) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) HP3PARApi(com.emc.storageos.hp3par.impl.HP3PARApi) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) Client(com.sun.jersey.api.client.Client) HP3PARException(com.emc.storageos.hp3par.impl.HP3PARException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 5 with HP3PARApi

use of com.emc.storageos.hp3par.impl.HP3PARApi in project coprhd-controller by CoprHD.

the class HP3PARApiFactory method init.

/**
 * Initialize HTTP client
 */
public void init() {
    _log.info("3PARDriver:HP3PARApiFactory init enter");
    _clientMap = new ConcurrentHashMap<String, HP3PARApi>();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setMaxTotalConnections(_maxConn);
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(_connTimeout);
    params.setSoTimeout(_socketConnTimeout);
    _connectionManager = new MultiThreadedHttpConnectionManager();
    _connectionManager.setParams(params);
    // close idle connections immediately
    _connectionManager.closeIdleConnections(0);
    HttpClient client = new HttpClient(_connectionManager);
    client.getParams().setConnectionManagerTimeout(connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });
    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080));
}
Also used : IOException(java.io.IOException) HttpMethodRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HP3PARApi(com.emc.storageos.hp3par.impl.HP3PARApi) Protocol(org.apache.commons.httpclient.protocol.Protocol) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Aggregations

HP3PARApi (com.emc.storageos.hp3par.impl.HP3PARApi)5 HP3PARException (com.emc.storageos.hp3par.impl.HP3PARException)4 IOException (java.io.IOException)3 PortStatisticsCommandResult (com.emc.storageos.hp3par.command.PortStatisticsCommandResult)2 ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)2 KeyManagementException (java.security.KeyManagementException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 CertificateException (java.security.cert.CertificateException)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 CPGCommandResult (com.emc.storageos.hp3par.command.CPGCommandResult)1 HostSetDetailsCommandResult (com.emc.storageos.hp3par.command.HostSetDetailsCommandResult)1 PortCommandResult (com.emc.storageos.hp3par.command.PortCommandResult)1 PortMembers (com.emc.storageos.hp3par.command.PortMembers)1 PortStatMembers (com.emc.storageos.hp3par.command.PortStatMembers)1 SystemCommandResult (com.emc.storageos.hp3par.command.SystemCommandResult)1 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)1 Client (com.sun.jersey.api.client.Client)1 ClientHandler (com.sun.jersey.api.client.ClientHandler)1 ApacheHttpClientHandler (com.sun.jersey.client.apache.ApacheHttpClientHandler)1 URLConnectionClientHandler (com.sun.jersey.client.urlconnection.URLConnectionClientHandler)1