cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nlivens <...@git.apache.org>
Subject [GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...
Date Mon, 21 Sep 2015 12:14:14 GMT
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39963698
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java
---
    @@ -285,60 +507,341 @@ public boolean deleteNuageVspDevice(DeleteNuageVspDeviceCmd cmd)
{
             return responseList;
         }
     
    -    @Override
    -    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
    -        try {
    -            initNuageScheduledTasks();
    -        } catch (Exception ce) {
    -            s_logger.warn("Failed to load NuageVsp configuration properties. Check if
the NuageVsp properties are configured correctly");
    +    private void registerNewNuageVspDevice(ConfigurationVO currentConfig, String registeredNuageVspDevice)
{
    +        if (currentConfig == null) {
    +            ConfigKey<String> configKey = new ConfigKey<String>("Advanced",
String.class, "nuagevsp.cms.id", registeredNuageVspDevice,
    +                    "<ACS Nuage VSP Device ID>:<Allocated VSD CMS ID> - Do
not edit", false);
    +            ConfigurationVO configuration = new ConfigurationVO("management-server",
configKey);
    +            _configDao.persist(configuration);
    +        } else {
    +            String newValue;
    +            String currentValue = currentConfig.getValue();
    +            if (StringUtils.isNotBlank(currentValue)) {
    +                newValue = currentValue + ";" + registeredNuageVspDevice;
    +            } else {
    +                newValue = registeredNuageVspDevice;
    +            }
    +            _configDao.update("nuagevsp.cms.id", newValue);
             }
    -        return true;
         }
     
    -    private void initNuageScheduledTasks() {
    -        Integer numOfSyncThreads = Integer.valueOf(_configDao.getValue(NuageVspManager.NuageVspSyncWorkers.key()));
    -        Integer syncUpIntervalInMinutes = Integer.valueOf(_configDao.getValue(NuageVspManager.NuageVspSyncInterval.key()));
    -
    -        if (numOfSyncThreads != null && syncUpIntervalInMinutes != null) {
    -            ThreadFactory threadFactory = new ThreadFactory() {
    -                public Thread newThread(Runnable runnable) {
    -                    Thread thread = new Thread(runnable, "Nuage Vsp sync task");
    -                    if (thread.isDaemon())
    -                        thread.setDaemon(false);
    -                    if (thread.getPriority() != Thread.NORM_PRIORITY)
    -                        thread.setPriority(Thread.NORM_PRIORITY);
    -                    return thread;
    +    private void auditHost(HostVO host) {
    +        _hostDao.loadDetails(host);
    +
    +        boolean validateDomains = true;
    +        List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
    +        if (!CollectionUtils.isEmpty(nuageVspDevices)) {
    +            for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
    +                ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
    +                String nuageVspCmsId = findNuageVspCmsIdForDevice(nuageVspDevice.getId(),
cmsIdConfig);
    +                SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.AUDIT,
nuageVspCmsId);
    +                SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(),
syncCmd);
    +
    +                if (answer != null && !answer.getSuccess()) {
    +                    s_logger.fatal("Nuage VSP Device with ID " + nuageVspDevice.getId()
+ " is configured with an unknown CMS ID!");
    +                    validateDomains = false;
    +                } else if (answer != null && answer.getSyncType() == SyncType.REGISTER)
{
    +                    registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":"
+ answer.getNuageVspCmsId());
                     }
    -            };
    -            scheduler = Executors.newScheduledThreadPool(numOfSyncThreads, threadFactory);
    -            scheduler.scheduleWithFixedDelay(new NuageVspSyncTask("FLOATING_IP"), ONE_MINUTE_MULTIPLIER
* 15, ONE_MINUTE_MULTIPLIER * syncUpIntervalInMinutes,
    -                    TimeUnit.MILLISECONDS);
    -            scheduler.scheduleWithFixedDelay(new NuageVspSyncTask("ENTERPRISE_NTWK_MACRO"),
ONE_MINUTE_MULTIPLIER * 15, ONE_MINUTE_MULTIPLIER * syncUpIntervalInMinutes,
    -                    TimeUnit.MILLISECONDS);
    -            scheduler
    -                    .scheduleWithFixedDelay(new NuageVspSyncTask("ENTERPRISE"), ONE_MINUTE_MULTIPLIER
* 15, ONE_MINUTE_MULTIPLIER * syncUpIntervalInMinutes, TimeUnit.MILLISECONDS);
    -        } else {
    -            s_logger.warn("NuageVsp configuration for syncWorkers=" + numOfSyncThreads
+ " syncInterval=" + syncUpIntervalInMinutes
    -                    + " could not be read properly. So, check if the properties are configured
properly in global properties");
    +            }
    +        }
    +
    +        if (validateDomains) {
    +            auditDomainsOnVsp(host, true, false);
             }
         }
     
    -    public class NuageVspSyncTask implements Runnable {
    +    private boolean auditDomainsOnVsp(HostVO host, boolean add, boolean remove) {
    +        List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
    +        if (!CollectionUtils.isEmpty(nuageVspDevices)) {
    +            _hostDao.loadDetails(host);
    +            List<DomainVO> allDomains = _domainDao.listAll();
    +            for (DomainVO domain : allDomains) {
    +                try {
    +                    SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(),
domain.getPath(), add, remove);
    +                    SyncDomainAnswer answer = (SyncDomainAnswer) _agentMgr.easySend(host.getId(),
cmd);
    +                    return answer.getSuccess();
    +                } catch (Exception e) {
    +                    s_logger.warn(e.getMessage());
    +                    return false;
    +                }
    +            }
    +        }
    +        return true;
    +    }
     
    -        private String nuageVspEntity;
    +    private String findNuageVspCmsIdForDevice(long deviceId, ConfigurationVO cmsIdConfig)
{
    +        String configValue = cmsIdConfig.getValue();
    +        if (StringUtils.isNotBlank(configValue)) {
    +            String[] configuredNuageVspDevices = configValue.split(";");
    +            for (String configuredNuageVspDevice : configuredNuageVspDevices) {
    +                if (configuredNuageVspDevice.startsWith(deviceId + ":")) {
    +                    return configuredNuageVspDevice.split(":")[1];
    --- End diff --
    
    This is a specific value that's being set from within the plugin itself, and this is in
a specific format like <ID>:<UUID>. I'll make the code fail safe though.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message