Search in sources :

Example 31 with ConfigurationException

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

the class ContrailManagerImpl method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    File configFile = PropertiesUtil.findConfigFile(configuration);
    FileInputStream fileStream = null;
    try {
        String hostname = null;
        int port = 0;
        if (configFile == null) {
            return false;
        } else {
            final Properties configProps = new Properties();
            fileStream = new FileInputStream(configFile);
            configProps.load(fileStream);
            String value = configProps.getProperty("management.db_sync_interval");
            if (value != null) {
                _dbSyncInterval = Integer.parseInt(value);
            }
            hostname = configProps.getProperty("api.hostname");
            String portStr = configProps.getProperty("api.port");
            if (portStr != null && portStr.length() > 0) {
                port = Integer.parseInt(portStr);
            }
        }
        _api = ApiConnectorFactory.build(hostname, port);
    } catch (IOException ex) {
        s_logger.warn("Unable to read " + configuration, ex);
        throw new ConfigurationException();
    } catch (Exception ex) {
        s_logger.debug("Exception in configure: " + ex);
        ex.printStackTrace();
        throw new ConfigurationException();
    } finally {
        IOUtils.closeQuietly(fileStream);
    }
    _controller = new ModelController(this, _api, _vmDao, _networksDao, _nicDao, _vlanDao, _ipAddressDao);
    try {
        _routerOffering = locateNetworkOffering(routerOfferingName, routerOfferingDisplayText, Provider.JuniperContrailRouter);
        _routerPublicOffering = locatePublicNetworkOffering(routerPublicOfferingName, routerPublicOfferingDisplayText, Provider.JuniperContrailRouter);
        _vpcRouterOffering = locateNetworkOffering(vpcRouterOfferingName, vpcRouterOfferingDisplayText, Provider.JuniperContrailVpcRouter);
        _vpcOffering = locateVpcOffering();
    } catch (Exception ex) {
        s_logger.debug("Exception in locating network offerings: " + ex);
        ex.printStackTrace();
        throw new ConfigurationException();
    }
    _eventHandler.subscribe();
    initializeDefaultVirtualNetworkModels();
    return true;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) Properties(java.util.Properties) ModelController(org.apache.cloudstack.network.contrail.model.ModelController) File(java.io.File) FileInputStream(java.io.FileInputStream) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException)

Example 32 with ConfigurationException

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

the class NuageVspManagerImpl method addNuageVspDevice.

@Override
public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
    final NuageVspResource resource = new NuageVspResource();
    final String deviceName = Network.Provider.NuageVsp.getName();
    ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    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");
    } else 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");
    }
    if (_nuageVspDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
    }
    // While the default VSD port is 8443, clustering via HAProxy will go over port 443 (CLOUD-58)
    int port = cmd.getPort() > 0 ? cmd.getPort() : 443;
    try {
        String apiVersion = null;
        String cmsUserPasswordBase64 = NuageVspUtil.encodePassword(cmd.getPassword());
        NuageVspResourceConfiguration resourceConfiguration = new NuageVspResourceConfiguration().guid(UUID.randomUUID().toString()).zoneId(String.valueOf(physicalNetwork.getDataCenterId())).hostName(cmd.getHostName()).cmsUser(cmd.getUserName()).cmsUserPassword(cmsUserPasswordBase64).port(String.valueOf(port)).apiVersion(NuageVspApiVersion.CURRENT.toString()).retryCount(NuageVspConstants.DEFAULT_API_RETRY_COUNT.toString()).retryInterval(NuageVspConstants.DEFAULT_API_RETRY_INTERVAL.toString()).apiRelativePath("/nuage");
        VspHost vspHost = resourceConfiguration.buildVspHost();
        NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(vspHost);
        VspApiDefaults apiDefaults = clientLoader.getNuageVspManagerClient().getApiDefaults();
        if (StringUtils.isNotBlank(cmd.getApiVersion())) {
            if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(cmd.getApiVersion())) {
                throw new CloudRuntimeException("Unsupported API version : " + cmd.getApiVersion());
            }
            apiVersion = cmd.getApiVersion();
        } else {
            boolean apiVersionFound = false;
            Map<NuageVspApiVersion, NuageVspApiVersion.Status> supportedVersions = clientLoader.getNuageVspManagerClient().getSupportedVersions();
            for (NuageVspApiVersion selectedVersion : supportedVersions.keySet()) {
                if (supportedVersions.get(selectedVersion) == NuageVspApiVersion.Status.CURRENT) {
                    apiVersion = selectedVersion.toString();
                    apiVersionFound = true;
                    break;
                }
            }
            if (!apiVersionFound) {
                throw new CloudRuntimeException("No supported API version found!");
            }
        }
        String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), apiDefaults.getRetryCount()));
        String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), apiDefaults.getRetryInterval()));
        resourceConfiguration.apiVersion(apiVersion).apiRelativePath("/nuage/api/" + apiVersion).retryCount(retryCount).retryInterval(retryInterval);
        Map<String, String> hostDetails = resourceConfiguration.build();
        resource.configure("Nuage VSD - " + cmd.getHostName(), Maps.<String, Object>newHashMap(hostDetails));
        Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, hostDetails);
        if (host == null) {
            throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
        }
        NuageVspDeviceVO nuageVspDevice = new NuageVspDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
        _nuageVspDao.persist(nuageVspDevice);
        DetailVO detail = new DetailVO(host.getId(), "nuagevspdeviceid", String.valueOf(nuageVspDevice.getId()));
        _hostDetailsDao.persist(detail);
        NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
        String cmsId;
        if (matchingNuageVspDevice != null) {
            cmsId = findNuageVspCmsIdForDeviceOrHost(matchingNuageVspDevice.getId(), matchingNuageVspDevice.getHostId());
        } else {
            SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
            SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
            if (answer != null && answer.getSuccess()) {
                cmsId = answer.getNuageVspCmsId();
            } else {
                throw new CloudRuntimeException("Failed to register CMS ID");
            }
        }
        host = findNuageVspHost(nuageVspDevice.getHostId());
        registerNewNuageVspDevice(host.getId(), cmsId);
        resourceConfiguration.nuageVspCmsId(cmsId);
        resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
        if (matchingNuageVspDevice == null) {
            auditDomainsOnVsp((HostVO) host, true);
        }
        return nuageVspDevice;
    } catch (ConfigurationException e) {
        s_logger.error("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
        throw new CloudRuntimeException("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
    } catch (ExecutionException ee) {
        s_logger.error("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
        throw new CloudRuntimeException("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
    }
}
Also used : NuageVspResourceConfiguration(com.cloud.network.resource.NuageVspResourceConfiguration) VspApiDefaults(net.nuage.vsp.acs.client.api.model.VspApiDefaults) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NuageVspApiVersion(net.nuage.vsp.acs.client.common.NuageVspApiVersion) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) VspHost(net.nuage.vsp.acs.client.api.model.VspHost) ExecutionException(java.util.concurrent.ExecutionException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Status(com.cloud.host.Status) NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) ExternalNetworkDeviceManager(org.apache.cloudstack.network.ExternalNetworkDeviceManager) VspHost(net.nuage.vsp.acs.client.api.model.VspHost) Host(com.cloud.host.Host) NuageVspResource(com.cloud.network.resource.NuageVspResource) DetailVO(com.cloud.host.DetailVO) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) SyncNuageVspCmsIdCommand(com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand) NuageVspPluginClientLoader(net.nuage.vsp.acs.client.api.NuageVspPluginClientLoader)

Example 33 with ConfigurationException

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

the class NuageVspResource method getCurrentStatus.

@Override
public PingCommand getCurrentStatus(long id) {
    if (Strings.isNullOrEmpty(_vspHost.getRestRelativePath())) {
        s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the relative path information");
        _shouldAudit = true;
        return null;
    }
    if (Strings.isNullOrEmpty(_vspHost.getCmsUserLogin()) || Strings.isNullOrEmpty(_vspHost.getCmsUserPassword())) {
        s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the CMS user information");
        _shouldAudit = true;
        return null;
    }
    try {
        login();
    } catch (ExecutionException | ConfigurationException e) {
        s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " + _vspHost.getCmsUserLogin(), e);
        _shouldAudit = true;
        return null;
    }
    PingNuageVspCommand pingNuageVspCommand = new PingNuageVspCommand(Host.Type.L2Networking, id, _shouldAudit);
    _shouldAudit = false;
    return pingNuageVspCommand;
}
Also used : PingNuageVspCommand(com.cloud.agent.api.PingNuageVspCommand) ConfigurationException(javax.naming.ConfigurationException) ExecutionException(java.util.concurrent.ExecutionException)

Example 34 with ConfigurationException

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

the class NuageVspResourceConfiguration method verifyInRange.

private int verifyInRange(String name, String value, int min, int max) throws ConfigurationException {
    verifyNotEmpty(name, value);
    int parsedValue;
    try {
        parsedValue = Integer.parseInt(value);
    } catch (NumberFormatException ex) {
        throw new ConfigurationException(name + " has to be between " + min + " and " + max);
    }
    if ((parsedValue < min) || (parsedValue > max)) {
        throw new ConfigurationException(name + " has to be between " + min + " and " + max);
    }
    return parsedValue;
}
Also used : ConfigurationException(javax.naming.ConfigurationException)

Example 35 with ConfigurationException

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

the class NuageVspCommandWrapper method execute.

@Override
public final Answer execute(final T command, final NuageVspResource nuageVspResource) {
    try {
        boolean success = executeNuageVspCommand(command, nuageVspResource);
        String detail = fillDetail(new StringBuilder(), command).append(" on ").append(nuageVspResource.getName()).toString();
        return new Answer(command, success, detail);
    } catch (NuageVspException | ConfigurationException e) {
        s_logger.error("Failure during " + command + " on " + nuageVspResource.getName(), e);
        return new Answer(command, e);
    }
}
Also used : Answer(com.cloud.agent.api.Answer) ConfigurationException(javax.naming.ConfigurationException) NuageVspException(net.nuage.vsp.acs.client.exception.NuageVspException)

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