use of com.emc.storageos.hp3par.command.HostSetDetailsCommandResult in project coprhd-controller by CoprHD.
the class HP3PARExpUnexpHelper method doHostProcessing.
private String doHostProcessing(List<Initiator> initiators, List<StorageVolume> volumes, Registry driverRegistry, LockManager driverLockManager) {
// will point host name in exclusive export and cluster name in shared export
String host = null;
String hostArray = null;
String clustArray = null;
// all volumes belong to same storage system
try {
// all initiators belong to same host
if (initiators.get(0).getInitiatorType().equals(Type.Host)) {
// Exclusive-Host export
// Some code is repeated with cluster for simplicity
HP3PARHostNameResult hostNameResult = get3parHostname(initiators, volumes.get(0).getStorageSystemId(), driverRegistry);
if (hostNameResult == null || hostNameResult.getAllInitiators() == false) {
// create a new host or add initiator to existing host
HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(volumes.get(0).getStorageSystemId(), driverRegistry);
ArrayList<String> portIds = new ArrayList<>();
for (Initiator init : initiators) {
portIds.add(init.getPort());
}
Integer persona = getPersona(initiators.get(0).getHostOsType());
if (hostNameResult != null && hostNameResult.getHostName() != null) {
// if 3PAR registered host is found
host = hostNameResult.getHostName();
hp3parApi.updateHost(host, portIds);
} else {
// use CoprHD host name for new host
host = initiators.get(0).getHostName();
hp3parApi.createHost(host, portIds, persona);
}
} else {
host = hostNameResult.getHostName();
}
// Host available
} else if (initiators.get(0).getInitiatorType().equals(Type.Cluster)) {
// Shared-Cluster export
clustArray = initiators.get(0).getClusterName();
HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(volumes.get(0).getStorageSystemId(), driverRegistry);
// Check if host exists, otherwise create
HP3PARHostNameResult hostNameResult = get3parHostname(initiators, volumes.get(0).getStorageSystemId(), driverRegistry);
if (hostNameResult == null || hostNameResult.getAllInitiators() == false) {
// create a new host or add initiator to existing host
ArrayList<String> portIds = new ArrayList<>();
for (Initiator init : initiators) {
portIds.add(init.getPort());
}
Integer persona = getPersona(initiators.get(0).getHostOsType());
if (hostNameResult != null && hostNameResult.getHostName() != null) {
// if 3PAR registered host is found
hostArray = hostNameResult.getHostName();
} else {
// use CoprHD host name
hostArray = initiators.get(0).getHostName();
}
hp3parApi.createHost(hostArray, portIds, persona);
} else {
hostArray = hostNameResult.getHostName();
}
// only one thread across all nodes should create cluster;
String lockName = volumes.get(0).getStorageSystemId() + clustArray;
if (driverLockManager.acquireLock(lockName, 10, TimeUnit.MINUTES)) {
// Check if cluster exists, otherwise create=>Cluster with +one host at a time
HostSetDetailsCommandResult hostsetRes = hp3parApi.getHostSetDetails(clustArray);
if (hostsetRes == null) {
hp3parApi.createHostSet(clustArray, initiators.get(0).getHostName());
} else {
// if this host is not part of the cluster add it
boolean present = false;
for (String setMember : hostsetRes.getSetmembers()) {
if (hostArray.compareTo(setMember) == 0) {
present = true;
break;
}
}
if (!present) {
// update cluster with this host
hp3parApi.updateHostSet(clustArray, hostArray);
}
}
// Cluster available
host = "set:" + clustArray;
driverLockManager.releaseLock(lockName);
} else {
_log.error("3PARDriver:doHostProcessing error: could not acquire thread lock to create cluster");
throw new HP3PARException("3PARDriver:doHostProcessing error: could not acquire thread lock to create cluster");
}
// lock
} else {
_log.error("3PARDriver:exportVolumesToInitiators error: Host/Cluster type not supported");
throw new HP3PARException("3PARDriver:exportVolumesToInitiators error: Host/Cluster type not supported");
}
} catch (Exception e) {
String msg = String.format("3PARDriver: Unable to export, error: %s", e);
_log.error(msg);
_log.error(CompleteError.getStackTrace(e));
return null;
}
return host;
}
use of com.emc.storageos.hp3par.command.HostSetDetailsCommandResult 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();
}
}
use of com.emc.storageos.hp3par.command.HostSetDetailsCommandResult in project coprhd-controller by CoprHD.
the class HP3PARApi method updateHostSet.
public HostSetDetailsCommandResult updateHostSet(String clustName, String hostName) throws Exception {
_log.info("3PARDriver:updateHostSet enter");
ClientResponse clientResp = null;
String body = "{\"action\": 1, \"setmembers\": [\"" + hostName + "\"]}";
final String path = MessageFormat.format(URI_HOSTSET_DETAILS, clustName);
_log.info("3PARDriver: updateHostSet path is {}, body is {}", path, body);
try {
clientResp = put(path, body);
if (clientResp == null) {
_log.error("3PARDriver:There is no response from 3PAR");
throw new HP3PARException("There is no response from 3PAR");
} else if (clientResp.getStatus() != 200) {
String errResp = getResponseDetails(clientResp);
throw new HP3PARException(errResp);
} else {
String responseString = clientResp.getEntity(String.class);
_log.info("3PARDriver:updateHostSet 3PAR response is {}", responseString);
HostSetDetailsCommandResult hostsetResult = new Gson().fromJson(sanitize(responseString), HostSetDetailsCommandResult.class);
return hostsetResult;
}
} catch (Exception e) {
throw e;
} finally {
if (clientResp != null) {
clientResp.close();
}
_log.info("3PARDriver:updateHostSet leave");
}
// end try/catch/finally
}
use of com.emc.storageos.hp3par.command.HostSetDetailsCommandResult in project coprhd-controller by CoprHD.
the class HP3PARApi method getHostSetDetails.
public HostSetDetailsCommandResult getHostSetDetails(String name) throws Exception {
_log.info("3PARDriver:getHostSetDetails enter");
ClientResponse clientResp = null;
final String path = MessageFormat.format(URI_HOSTSET_DETAILS, name);
_log.info("3PARDriver: getHostSetDetails path is {}", path);
try {
clientResp = get(path);
if (clientResp == null) {
_log.error("3PARDriver:There is no response from 3PAR");
throw new HP3PARException("There is no response from 3PAR");
} else if (clientResp.getStatus() != 200) {
String errResp = getResponseDetails(clientResp);
if (clientResp.getStatus() == 404 && errResp.contains("code: 102")) {
// Host set does not exists
return null;
} else {
throw new HP3PARException(errResp);
}
} else {
String responseString = clientResp.getEntity(String.class);
_log.info("3PARDriver:getHostSetDetails 3PAR response is {}", responseString);
HostSetDetailsCommandResult hostsetResult = new Gson().fromJson(sanitize(responseString), HostSetDetailsCommandResult.class);
return hostsetResult;
}
} catch (Exception e) {
throw e;
} finally {
if (clientResp != null) {
clientResp.close();
}
_log.info("3PARDriver:getHostSetDetails leave");
}
// end try/catch/finally
}
Aggregations