use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class DCNMDialog method getClient.
/**
* Initialize the client interface.
*
* @param ipaddress
* @param username
* @param password
* @param smisport
* @return WBEMClient
*/
public WBEMClient getClient(String ipaddress, String username, String password, Integer smisport) {
try {
WBEMClient client = WBEMClientFactory.getClient(WBEMClientConstants.PROTOCOL_CIMXML);
CIMObjectPath path = CimObjectPathCreator.createInstance("http", ipaddress, smisport.toString(), _namespace, null, null);
final Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal(username));
subject.getPrivateCredentials().add(new PasswordCredential(password));
client.initialize(path, subject, new Locale[] { Locale.US });
_client = client;
return client;
} catch (WBEMException ex) {
_log.error("Can't open client: WBEMException: " + ex.getLocalizedMessage());
return null;
}
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class DCNMDialog method startSession.
/**
* @param client
* @param zonesetService -- Instance of the ZonesetService
* @return true iff session is started
* @throws NetworkControllerSessionLockedException
* @throws WBEMException
*/
@SuppressWarnings("rawtypes")
public boolean startSession(WBEMClient client, CIMInstance zonesetService) throws NetworkControllerSessionLockedException, WBEMException {
UnsignedInteger32 result = null;
try {
int sessionState = cimIntegerProperty(zonesetService, "SessionState");
int RequestedSessionState = cimIntegerProperty(zonesetService, "RequestedSessionState");
if (sessionState == _notApplicable) {
// no session control implemented by this agent
return true;
}
// if (sessionState != _ended || RequestedSessionState != _noChange) {
// _log.error("Zone session is locked by another user or agent.");
// throw new NetworkControllerSessionLockedException(
// "Zone session is locked by another user or agent.");
// }
CIMArgument[] inargs = new CIMArgument[] { _cimArgumentFactory.uint16("RequestedSessionState", _started) };
result = (UnsignedInteger32) client.invokeMethod(zonesetService.getObjectPath(), "SessionControl", inargs, new CIMArgument[1]);
_log.info("Start session returned code: " + result.intValue());
return (result.intValue() == 0 || result.intValue() == 32772);
} catch (WBEMException ex) {
_log.error("Encountered an exception while trying to start a zone session." + ex.getLocalizedMessage());
throw ex;
}
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class DCNMDialog method getZonesetsInVsan.
/**
* Returns the zonesets in a VSAN as given by its CIMInstance.
* This generates the nested objects Zone and ZoneMember in the Zonesets.
*
* @param vsanIns CIMInstance of vsan
* @return List<Zoneset>
* @throws javax.wbem.WBEMException
*/
private List<Zoneset> getZonesetsInVsan(CIMInstance vsanIns) throws WBEMException {
List<Zoneset> inactiveZonesets = new ArrayList<Zoneset>();
Zoneset activeZoneset = null;
// Iterate through the zonesets.
CloseableIterator<CIMInstance> zstIt = null;
try {
zstIt = _client.associatorInstances(vsanIns.getObjectPath(), "CIM_HostedCollection", "CISCO_Zoneset", null, null, false, null);
while (zstIt.hasNext()) {
CIMInstance zsIns = zstIt.next();
Zoneset zs = makeZoneset(zsIns);
_log.debug("zoneset: " + zs.name);
if (zs.active == true) {
activeZoneset = zs;
} else {
inactiveZonesets.add(zs);
}
}
} catch (WBEMException ex) {
// Problem where iterator isn't returned in associators();
} finally {
if (zstIt != null) {
zstIt.close();
}
}
List<Zoneset> zonesets = new ArrayList<Zoneset>();
if (activeZoneset != null) {
zonesets.add(activeZoneset);
}
zonesets.addAll(inactiveZonesets);
return zonesets;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class HDSCommunicationInterface method getCIMClient.
/**
* Creates a new WEBClient for a given IP, based on AccessProfile
*
* @param accessProfile
* : AccessProfile for the providers
* @throws WBEMException
* : if WBEMException while creating the WBEMClient
* @throws SMIPluginException
* @return WBEMClient : initialized instance of WBEMClientCIMXML
*/
private WBEMClient getCIMClient(AccessProfile accessProfile) throws Exception {
String protocol = Boolean.valueOf(accessProfile.getSslEnable()) ? CimConstants.SECURE_PROTOCOL : CimConstants.DEFAULT_PROTOCOL;
CIMObjectPath path = CimObjectPathCreator.createInstance(protocol, accessProfile.getIpAddress(), Integer.toString(accessProfile.getPortNumber()), accessProfile.getInteropNamespace(), null, null);
try {
Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal(accessProfile.getUserName()));
subject.getPrivateCredentials().add(new PasswordCredential(accessProfile.getPassword()));
wbemClient = WBEMClientFactory.getClient(CimConstants.CIM_CLIENT_PROTOCOL);
// Operations block by default, so a timeout must be set in case the
// CIM server becomes unreachable.
// Commenting out, as timeout had been moved to cimom.properties
// file
// _cimClient.setProperty(WBEMClientConstants.PROP_TIMEOUT,
// CimConstants.CIM_CLIENT_TIMEOUT);
wbemClient.initialize(path, subject, null);
} catch (Exception e) {
_logger.error("Could not establish connection for {}", accessProfile.getIpAddress(), e);
wbemClient.close();
throw e;
}
return wbemClient;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class CIMConnectionFactory method checkConnectionliveness.
/**
* To-Do: check for Connection liveness 1. if null, add a new Connection. 2.
* if connection present, then check for liveness.
*
* @return boolean
*/
public boolean checkConnectionliveness(CimConnection connection) {
boolean isLive = false;
if (null == connection) {
return isLive;
}
WBEMClient wbemClient = connection.getCimClient();
_log.debug("copPath:{}", _cop);
try {
// Call the provider to get computer systems.
wbemClient.enumerateInstanceNames(_cop);
isLive = true;
} catch (WBEMException wbemEx) {
_log.error("Invalid connection found for ipAddress: {}", connection.getHost());
}
return isLive;
}
Aggregations