use of javax.naming.ConfigurationException in project cloudstack by apache.
the class GloboDnsElement method addGloboDnsHost.
@Override
@DB
public Host addGloboDnsHost(Long physicalNetworkId, final String username, final String password, String url) {
if (username == null || username.trim().isEmpty()) {
throw new InvalidParameterValueException("Invalid username: " + username);
}
if (password == null || password.trim().isEmpty()) {
throw new InvalidParameterValueException("Invalid password: " + password);
}
if (url == null || url.trim().isEmpty()) {
throw new InvalidParameterValueException("Invalid url: " + url);
}
// validate physical network and zone
// Check if physical network exists
PhysicalNetwork pNtwk = null;
if (physicalNetworkId != null) {
pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
if (pNtwk == null) {
throw new InvalidParameterValueException("Unable to find a physical network having the specified physical network id");
}
} else {
throw new InvalidParameterValueException("Invalid physicalNetworkId: " + physicalNetworkId);
}
final Long zoneId = pNtwk.getDataCenterId();
final Map<String, String> params = new HashMap<String, String>();
params.put("guid", "globodns-" + String.valueOf(zoneId));
params.put("zoneId", String.valueOf(zoneId));
params.put("name", Provider.GloboDns.getName());
params.put("url", url);
params.put("username", username);
params.put("password", password);
final Map<String, Object> hostDetails = new HashMap<String, Object>();
hostDetails.putAll(params);
Host host = Transaction.execute(new TransactionCallbackWithException<Host, CloudRuntimeException>() {
@Override
public Host doInTransaction(TransactionStatus status) throws CloudRuntimeException {
try {
GloboDnsResource resource = new GloboDnsResource();
resource.configure(Provider.GloboDns.getName(), hostDetails);
Host host = _resourceMgr.addHost(zoneId, resource, resource.getType(), params);
if (host == null) {
throw new CloudRuntimeException("Failed to add GloboDNS host");
}
// Validate username and password by logging in
SignInCommand cmd = new SignInCommand(username, password);
Answer answer = callCommand(cmd, zoneId);
if (answer == null || !answer.getResult()) {
// Could not sign in on GloboDNS
throw new ConfigurationException("Could not sign in on GloboDNS. Please verify URL, username and password.");
}
return host;
} catch (ConfigurationException e) {
throw new CloudRuntimeException(e);
}
}
});
return host;
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class F5BigIpResource method configure.
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
try {
_name = (String) params.get("name");
if (_name == null) {
throw new ConfigurationException("Unable to find name");
}
_zoneId = (String) params.get("zoneId");
if (_zoneId == null) {
throw new ConfigurationException("Unable to find zone");
}
_ip = (String) params.get("ip");
if (_ip == null) {
throw new ConfigurationException("Unable to find IP");
}
_username = (String) params.get("username");
if (_username == null) {
throw new ConfigurationException("Unable to find username");
}
_password = (String) params.get("password");
if (_password == null) {
throw new ConfigurationException("Unable to find password");
}
_publicInterface = (String) params.get("publicinterface");
if (_publicInterface == null) {
throw new ConfigurationException("Unable to find public interface");
}
_privateInterface = (String) params.get("privateinterface");
if (_privateInterface == null) {
throw new ConfigurationException("Unable to find private interface");
}
_numRetries = NumbersUtil.parseInt((String) params.get("numretries"), 1);
_guid = (String) params.get("guid");
if (_guid == null) {
throw new ConfigurationException("Unable to find the guid");
}
login();
return true;
} catch (Exception e) {
throw new ConfigurationException(e.getMessage());
}
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class NetworkUsageManagerImpl method addTrafficMonitor.
@Override
public Host addTrafficMonitor(AddTrafficMonitorCmd cmd) {
long zoneId = cmd.getZoneId();
DataCenterVO zone = _dcDao.findById(zoneId);
String zoneName;
if (zone == null) {
throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
} else {
zoneName = zone.getName();
}
List<HostVO> trafficMonitorsInZone = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.TrafficMonitor, zoneId);
if (trafficMonitorsInZone.size() != 0) {
throw new InvalidParameterValueException("Already added an traffic monitor in zone: " + zoneName);
}
URI uri;
try {
uri = new URI(cmd.getUrl());
} catch (Exception e) {
s_logger.debug(e);
throw new InvalidParameterValueException(e.getMessage());
}
String ipAddress = uri.getHost();
//String numRetries = params.get("numretries");
//String timeout = params.get("timeout");
TrafficSentinelResource resource = new TrafficSentinelResource();
String guid = getTrafficMonitorGuid(zoneId, NetworkUsageResourceName.TrafficSentinel, ipAddress);
Map<String, Object> hostParams = new HashMap<String, Object>();
hostParams.put("zone", String.valueOf(zoneId));
hostParams.put("ipaddress", ipAddress);
hostParams.put("url", cmd.getUrl());
hostParams.put("inclZones", (cmd.getInclZones() != null) ? cmd.getInclZones() : _TSinclZones);
hostParams.put("exclZones", (cmd.getExclZones() != null) ? cmd.getExclZones() : _TSexclZones);
hostParams.put("guid", guid);
hostParams.put("name", guid);
try {
resource.configure(guid, hostParams);
} catch (ConfigurationException e) {
throw new CloudRuntimeException(e.getMessage());
}
Map<String, String> hostDetails = new HashMap<String, String>();
hostDetails.put("url", cmd.getUrl());
hostDetails.put("last_collection", "" + System.currentTimeMillis());
if (cmd.getInclZones() != null) {
hostDetails.put("inclZones", cmd.getInclZones());
}
if (cmd.getExclZones() != null) {
hostDetails.put("exclZones", cmd.getExclZones());
}
Host trafficMonitor = _resourceMgr.addHost(zoneId, resource, Host.Type.TrafficMonitor, hostDetails);
return trafficMonitor;
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class RabbitMQEventBus method configure.
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
try {
if (amqpHost == null || amqpHost.isEmpty()) {
throw new ConfigurationException("Unable to get the AMQP server details");
}
if (username == null || username.isEmpty()) {
throw new ConfigurationException("Unable to get the username details");
}
if (password == null || password.isEmpty()) {
throw new ConfigurationException("Unable to get the password details");
}
if (amqpExchangeName == null || amqpExchangeName.isEmpty()) {
throw new ConfigurationException("Unable to get the _exchange details on the AMQP server");
}
if (port == null) {
throw new ConfigurationException("Unable to get the port details of AMQP server");
}
if (useSsl != null && !useSsl.isEmpty()) {
if (!useSsl.equalsIgnoreCase("true") && !useSsl.equalsIgnoreCase("false")) {
throw new ConfigurationException("Invalid configuration parameter for 'ssl'.");
}
}
if (retryInterval == null) {
// default to 10s to try out reconnect
retryInterval = 10000;
}
} catch (NumberFormatException e) {
throw new ConfigurationException("Invalid port number/retry interval");
}
s_subscribers = new ConcurrentHashMap<String, Ternary<String, Channel, EventSubscriber>>();
executorService = Executors.newCachedThreadPool();
disconnectHandler = new DisconnectHandler();
blockedConnectionHandler = new BlockedConnectionHandler();
return true;
}
use of javax.naming.ConfigurationException in project cloudstack by apache.
the class KVMStorageProcessor method configure.
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
storageLayer = new JavaStorageLayer();
storageLayer.configure("StorageLayer", params);
String storageScriptsDir = (String) params.get("storage.scripts.dir");
if (storageScriptsDir == null) {
storageScriptsDir = getDefaultStorageScriptsDir();
}
_createTmplPath = Script.findScript(storageScriptsDir, "createtmplt.sh");
if (_createTmplPath == null) {
throw new ConfigurationException("Unable to find the createtmplt.sh");
}
_manageSnapshotPath = Script.findScript(storageScriptsDir, "managesnapshot.sh");
if (_manageSnapshotPath == null) {
throw new ConfigurationException("Unable to find the managesnapshot.sh");
}
final String value = (String) params.get("cmds.timeout");
_cmdsTimeout = NumbersUtil.parseInt(value, 7200) * 1000;
return true;
}
Aggregations