Search in sources :

Example 86 with ConfigurationException

use of javax.naming.ConfigurationException in project CloudStack-archive by CloudStack-extras.

the class JettyVmDataServer method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    boolean success = true;
    try {
        int vmDataPort = 80;
        int fileservingPort = 8000;
        _vmDataDir = (String) params.get("vm.data.dir");
        String port = (String) params.get("vm.data.port");
        if (port != null) {
            vmDataPort = Integer.parseInt(port);
        }
        port = (String) params.get("file.server.port");
        if (port != null) {
            fileservingPort = Integer.parseInt(port);
        }
        _hostIp = (String) params.get("host.ip");
        if (_vmDataDir == null) {
            _vmDataDir = "/var/www/html";
        }
        success = _fs.mkdirs(_vmDataDir);
        success = success && buildIpVmMap();
        if (success) {
            setupJetty(vmDataPort, fileservingPort);
        }
    } catch (Exception e) {
        s_logger.warn("Failed to configure jetty", e);
        throw new ConfigurationException("Failed to configure jetty!!");
    }
    return success;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) ServletException(javax.servlet.ServletException) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 87 with ConfigurationException

use of javax.naming.ConfigurationException in project cloudstack by apache.

the class NuageVspResourceConfiguration method validate.

public void validate() throws ConfigurationException {
    verifyNotNull("name", _name);
    verifyNotNull("guid", _guid);
    verifyNotNull("zone", _zoneId);
    verifyNotNull("hostname", _hostName);
    verifyNotNull("CMS username", _cmsUser);
    verifyNotNull("CMS password", _cmsUserPassword);
    verifyNotEmpty("API version", _apiVersion);
    try {
        new NuageVspApiVersion(_apiVersion);
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException("Incorrect API version");
    }
    verifyNotEmpty("number of retries", _retryCount);
    verifyNotEmpty("retry interval", _retryInterval);
}
Also used : ConfigurationException(javax.naming.ConfigurationException) NuageVspApiVersion(net.nuage.vsp.acs.client.common.NuageVspApiVersion)

Example 88 with ConfigurationException

use of javax.naming.ConfigurationException in project cloudstack by apache.

the class NuageVspSyncCmsIdCommandWrapper method execute.

@Override
public SyncNuageVspCmsIdAnswer execute(SyncNuageVspCmsIdCommand cmd, NuageVspResource nuageVspResource) {
    NuageVspManagerClient client = null;
    try {
        client = nuageVspResource.getNuageVspManagerClient();
        Pair<Boolean, String> answer;
        switch(cmd.getSyncType()) {
            case REGISTER:
                String registeredNuageVspCmsId = client.registerNuageVspCmsId();
                answer = Pair.of(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId);
                break;
            case UNREGISTER:
                boolean success = client.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
                answer = Pair.of(success, cmd.getNuageVspCmsId());
                break;
            default:
                answer = client.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncNuageVspCmsIdCommand.SyncType.AUDIT_ONLY);
                break;
        }
        return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    } catch (ConfigurationException | NuageVspException e) {
        return new SyncNuageVspCmsIdAnswer(cmd, e, cmd.getSyncType());
    }
}
Also used : NuageVspManagerClient(net.nuage.vsp.acs.client.api.NuageVspManagerClient) ConfigurationException(javax.naming.ConfigurationException) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) NuageVspException(net.nuage.vsp.acs.client.exception.NuageVspException)

Example 89 with ConfigurationException

use of javax.naming.ConfigurationException in project cloudstack by apache.

the class NuageVspManagerImpl method updateNuageVspDevice.

@Override
public NuageVspDeviceVO updateNuageVspDevice(UpdateNuageVspDeviceCmd command) {
    NuageVspResource resource = new NuageVspResource();
    final String deviceName = Network.Provider.NuageVsp.getName();
    ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = command.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
    }
    if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
    }
    HostVO nuageVspHost = null;
    NuageVspDeviceVO nuageVspDevice = null;
    List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    if (nuageVspDevices == null || nuageVspDevices.isEmpty()) {
        throw new CloudRuntimeException("Nuage VSD is not configured on physical network " + physicalNetworkId);
    } else {
        nuageVspDevice = nuageVspDevices.iterator().next();
        nuageVspHost = _hostDao.findById(nuageVspDevice.getHostId());
        _hostDao.loadDetails(nuageVspHost);
    }
    boolean resourceConfigurationChanged = false;
    NuageVspResourceConfiguration resourceConfiguration = NuageVspResourceConfiguration.fromConfiguration(nuageVspHost.getDetails());
    if (!Strings.isNullOrEmpty(command.getHostName()) && !command.getHostName().equals(resourceConfiguration.hostName())) {
        resourceConfiguration.hostName(command.getHostName());
        resourceConfigurationChanged = true;
    }
    if (!Strings.isNullOrEmpty(command.getUserName()) && !command.getUserName().equals(resourceConfiguration.cmsUser())) {
        resourceConfiguration.cmsUser(command.getUserName());
        resourceConfigurationChanged = true;
    }
    if (!Strings.isNullOrEmpty(command.getPassword())) {
        String encodedNewPassword = NuageVspUtil.encodePassword(command.getPassword());
        if (!encodedNewPassword.equals(resourceConfiguration.cmsUserPassword())) {
            resourceConfiguration.cmsUserPassword(encodedNewPassword);
            resourceConfigurationChanged = true;
        }
    }
    if (command.getPort() != null && command.getPort() != Integer.parseInt(resourceConfiguration.port())) {
        resourceConfiguration.port(String.valueOf(command.getPort()));
        resourceConfigurationChanged = true;
    }
    String apiVersion = MoreObjects.firstNonNull(command.getApiVersion(), resourceConfiguration.apiVersion());
    NuageVspApiVersion apiVersionObj = NuageVspApiVersion.fromString(apiVersion);
    NuageVspApiVersion apiVersionCurrent = null;
    try {
        apiVersionCurrent = resourceConfiguration.getApiVersion();
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Current version is not configured correctly");
    }
    if (command.getApiVersion() != null) {
        if (apiVersionObj.compareTo(apiVersionCurrent) < 0) {
            throw new CloudRuntimeException("Downgrading is not supported");
        }
        GetApiDefaultsCommand apiDefaultsCmd = new GetApiDefaultsCommand();
        GetApiDefaultsAnswer apiDefaultsAnswer = (GetApiDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), apiDefaultsCmd);
        SupportedApiVersionCommand supportedApiVersionCmd = new SupportedApiVersionCommand(apiVersion);
        Answer supportedApiVersionAnswer = _agentMgr.easySend(nuageVspHost.getId(), supportedApiVersionCmd);
        if (!supportedApiVersionAnswer.getResult()) {
            throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + apiDefaultsAnswer.getApiDefaults().getVersion());
        }
        String apiRelativePath = "/nuage/api/" + apiVersion;
        if (!apiRelativePath.equals(resourceConfiguration.apiRelativePath())) {
            resourceConfiguration.apiVersion(apiVersion);
            resourceConfiguration.apiRelativePath(apiRelativePath);
            resourceConfigurationChanged = true;
        }
    }
    if (command.getApiRetryCount() != null && resourceConfiguration.retryCount() != null) {
        final int retryCount = Integer.parseInt(resourceConfiguration.retryCount());
        if (command.getApiRetryCount() != retryCount) {
            resourceConfiguration.retryCount(String.valueOf(command.getApiRetryCount()));
            resourceConfigurationChanged = true;
        }
    }
    if (command.getApiRetryInterval() != null && resourceConfiguration.retryInterval() != null) {
        final int apiRetryInterval = Integer.parseInt(resourceConfiguration.retryInterval());
        if (command.getApiRetryInterval() != apiRetryInterval) {
            resourceConfiguration.retryInterval(String.valueOf(command.getApiRetryInterval()));
            resourceConfigurationChanged = true;
        }
    }
    if (!resourceConfigurationChanged) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No change in the NuageVsp device parameters. None of the NuageVsp device parameters are modified");
        }
        return nuageVspDevice;
    }
    Map<String, String> config = resourceConfiguration.build();
    try {
        resource.validate(config);
        UpdateNuageVspDeviceCommand cmd = new UpdateNuageVspDeviceCommand(resourceConfiguration);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("UpdateNuageVspDeviceCommand failed");
            if ((null != answer) && (null != answer.getDetails())) {
                throw new CloudRuntimeException(answer.getDetails());
            }
        }
        _hostDetailsDao.persist(nuageVspDevice.getHostId(), config);
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Failed to update Nuage VSP device " + nuageVspDevice.getId() + " with parameters " + resourceConfiguration, e);
    }
    return nuageVspDevice;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) NuageVspResourceConfiguration(com.cloud.network.resource.NuageVspResourceConfiguration) ExternalNetworkDeviceManager(org.apache.cloudstack.network.ExternalNetworkDeviceManager) GetApiDefaultsCommand(com.cloud.agent.api.manager.GetApiDefaultsCommand) SupportedApiVersionCommand(com.cloud.agent.api.manager.SupportedApiVersionCommand) UpdateNuageVspDeviceCommand(com.cloud.agent.api.manager.UpdateNuageVspDeviceCommand) HostVO(com.cloud.host.HostVO) NuageVspResource(com.cloud.network.resource.NuageVspResource) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NuageVspApiVersion(net.nuage.vsp.acs.client.common.NuageVspApiVersion)

Example 90 with ConfigurationException

use of javax.naming.ConfigurationException in project cloudstack by apache.

the class BridgeVifDriver method configure.

@Override
public void configure(Map<String, Object> params) throws ConfigurationException {
    super.configure(params);
    // Set the domr scripts directory
    params.put("domr.scripts.dir", "scripts/network/domr/kvm");
    String networkScriptsDir = (String) params.get("network.scripts.dir");
    if (networkScriptsDir == null) {
        networkScriptsDir = "scripts/vm/network/vnet";
    }
    bridgeNameSchema = (String) params.get("network.bridge.name.schema");
    String value = (String) params.get("scripts.timeout");
    _timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000;
    _modifyVlanPath = Script.findScript(networkScriptsDir, "modifyvlan.sh");
    if (_modifyVlanPath == null) {
        throw new ConfigurationException("Unable to find modifyvlan.sh");
    }
    _modifyVxlanPath = Script.findScript(networkScriptsDir, "modifyvxlan.sh");
    if (_modifyVxlanPath == null) {
        throw new ConfigurationException("Unable to find modifyvxlan.sh");
    }
    libvirtVersion = (Long) params.get("libvirtVersion");
    if (libvirtVersion == null) {
        libvirtVersion = 0L;
    }
    try {
        createControlNetwork();
    } catch (LibvirtException e) {
        throw new ConfigurationException(e.getMessage());
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

ConfigurationException (javax.naming.ConfigurationException)168 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)57 IOException (java.io.IOException)44 HashMap (java.util.HashMap)39 File (java.io.File)23 Map (java.util.Map)21 InternalErrorException (com.cloud.exception.InternalErrorException)19 Properties (java.util.Properties)19 StorageLayer (com.cloud.storage.StorageLayer)18 Processor (com.cloud.storage.template.Processor)17 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 Answer (com.cloud.agent.api.Answer)16 ServerResource (com.cloud.resource.ServerResource)16 TemplateLocation (com.cloud.storage.template.TemplateLocation)16 Script (com.cloud.utils.script.Script)16 FormatInfo (com.cloud.storage.template.Processor.FormatInfo)14 FileNotFoundException (java.io.FileNotFoundException)14 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)13 Host (com.cloud.host.Host)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)11