Search in sources :

Example 36 with ConfigurationException

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;
}
Also used : SignInCommand(com.globo.globodns.cloudstack.commands.SignInCommand) HashMap(java.util.HashMap) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) GloboDnsResource(com.globo.globodns.cloudstack.resource.GloboDnsResource) Answer(com.cloud.agent.api.Answer) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Example 37 with ConfigurationException

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());
    }
}
Also used : ConfigurationException(javax.naming.ConfigurationException) ExecutionException(com.cloud.utils.exception.ExecutionException) RemoteException(java.rmi.RemoteException) ConfigurationException(javax.naming.ConfigurationException)

Example 38 with ConfigurationException

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;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) Host(com.cloud.host.Host) URI(java.net.URI) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TrafficSentinelResource(com.cloud.network.resource.TrafficSentinelResource)

Example 39 with ConfigurationException

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;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) Ternary(com.cloud.utils.Ternary)

Example 40 with ConfigurationException

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;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) JavaStorageLayer(com.cloud.storage.JavaStorageLayer)

Aggregations

ConfigurationException (javax.naming.ConfigurationException)114 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)44 IOException (java.io.IOException)30 HashMap (java.util.HashMap)28 File (java.io.File)16 Map (java.util.Map)14 Properties (java.util.Properties)13 Answer (com.cloud.agent.api.Answer)12 InternalErrorException (com.cloud.exception.InternalErrorException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 ServerResource (com.cloud.resource.ServerResource)11 FileNotFoundException (java.io.FileNotFoundException)11 Host (com.cloud.host.Host)10 Processor (com.cloud.storage.template.Processor)10 FileInputStream (java.io.FileInputStream)10 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 StorageLayer (com.cloud.storage.StorageLayer)9 TemplateLocation (com.cloud.storage.template.TemplateLocation)9 TransactionStatus (com.cloud.utils.db.TransactionStatus)9