Return-Path: X-Original-To: apmail-cloudstack-dev-archive@www.apache.org Delivered-To: apmail-cloudstack-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E0E5C1787C for ; Fri, 18 Sep 2015 22:12:26 +0000 (UTC) Received: (qmail 7211 invoked by uid 500); 18 Sep 2015 22:12:26 -0000 Delivered-To: apmail-cloudstack-dev-archive@cloudstack.apache.org Received: (qmail 7153 invoked by uid 500); 18 Sep 2015 22:12:26 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 7137 invoked by uid 99); 18 Sep 2015 22:12:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2015 22:12:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 217D8E03D2; Fri, 18 Sep 2015 22:12:26 +0000 (UTC) From: jburwell To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org References: In-Reply-To: Subject: [GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin... Content-Type: text/plain Message-Id: <20150918221226.217D8E03D2@git1-us-west.apache.org> Date: Fri, 18 Sep 2015 22:12:26 +0000 (UTC) Github user jburwell commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/801#discussion_r39906365 --- 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 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 configKey = new ConfigKey("Advanced", String.class, "nuagevsp.cms.id", registeredNuageVspDevice, + ": - 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 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 nuageVspDevices = _nuageVspDao.listByHost(host.getId()); + if (!CollectionUtils.isEmpty(nuageVspDevices)) { + _hostDao.loadDetails(host); + List 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]; + } + } + } + return null; + } - public NuageVspSyncTask(String nuageVspEntity) { - this.nuageVspEntity = nuageVspEntity; + public List getDnsDetails(Network network) { + List dnsServers = null; + Boolean configureDns = Boolean.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigDns.key())); + if (configureDns) { + Boolean configureExternalDns = Boolean.valueOf(_configDao.getValue(NuageVspManager.NuageVspDnsExternal.key())); + DataCenterVO dc = _dataCenterDao.findById(network.getDataCenterId()); + dnsServers = new ArrayList(); + if (configureExternalDns) { + if (dc.getDns1() != null && dc.getDns1().length() > 0) { + dnsServers.add(dc.getDns1()); + } + if (dc.getDns2() != null && dc.getDns2().length() > 0) { + dnsServers.add(dc.getDns2()); + } + } else { + if (dc.getInternalDns1() != null && dc.getInternalDns1().length() > 0) { + dnsServers.add(dc.getInternalDns1()); + } + if (dc.getInternalDns2() != null && dc.getInternalDns2().length() > 0) { + dnsServers.add(dc.getInternalDns2()); + } + } } + return dnsServers; + } - public String getNuageVspEntity() { - return nuageVspEntity; + public List getGatewaySystemIds() { + List gatewayIds = null; + String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key())); + if (StringUtils.isNotBlank(gatewaySystemIds)) { + StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ","); + gatewayIds = new ArrayList(tokens.countTokens()); + while (tokens.hasMoreTokens()) + { + gatewayIds.add(tokens.nextToken()); + } } + return gatewayIds; + } + + @Override + public boolean preStateTransitionEvent(Status oldState, Status.Event event, Status newState, Host host, boolean status, Object opaque) { + return true; + } - @Override - public void run() { - nuageVspSync.syncWithNuageVsp(nuageVspEntity); + @Override + public boolean postStateTransitionEvent(StateMachine2.Transition transition, Host vo, boolean status, Object opaque) { + // Whenever a Nuage VSP Host comes up, check if all CS domains are present and check if the CMS ID is valid + if (transition.getToState() == Status.Up && vo instanceof HostVO) { + auditHost((HostVO) vo); } + return true; + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + initMessageBusListeners(); + initNuageVspResourceListeners(); + initNuageNetworkOffering(); + initNuageVspVpcOffering(); + Status.getStateMachine().registerListener(this); + return true; + } + + @DB + private void initMessageBusListeners() { + // Create corresponding enterprise and profile in VSP when creating a CS Domain + _messageBus.subscribe(DomainManager.MESSAGE_ADD_DOMAIN_EVENT, new MessageSubscriber() { + @Override + public void onPublishMessage(String senderAddress, String subject, Object args) { + Long domainId = (Long) args; + Domain domain = _domainDao.findById(domainId); + + try { + _domainDao.acquireInLockTable(domain.getId()); + + List nuageVspDevices = _nuageVspDao.listAll(); + for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) { + HostVO host = findNuageVspHost(nuageVspDevice.getHostId()); + SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), true, false); + _agentMgr.easySend(host.getId(), cmd); + } + } catch (Exception e) { + s_logger.error(e.getMessage()); + } finally { + _domainDao.releaseFromLockTable(domain.getId()); + } + } + }); + + // Delete corresponding enterprise and profile in VSP when deleting a CS Domain + _messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() { + @Override + public void onPublishMessage(String senderAddress, String subject, Object args) { + DomainVO domain = (DomainVO) args; + try { + List nuageVspDevices = _nuageVspDao.listAll(); + for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) { + HostVO host = findNuageVspHost(nuageVspDevice.getHostId()); + SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), false, true); + _agentMgr.easySend(host.getId(), cmd); + } + } catch (Exception e) { + s_logger.error(e.getMessage()); + } + } + }); + } + + @DB + private void initNuageVspResourceListeners() { + _agentMgr.registerForHostEvents(new Listener() { + @Override + public boolean processAnswers(long agentId, long seq, Answer[] answers) { + return true; + } + + @Override + public boolean processCommands(long agentId, long seq, Command[] commands) { + if (commands != null && commands.length == 1) { + Command command = commands[0]; + if (command instanceof PingNuageVspCommand) { + PingNuageVspCommand pingNuageVspCommand = (PingNuageVspCommand) command; + if (pingNuageVspCommand.shouldAudit()) { + Host host = _hostDao.findById(pingNuageVspCommand.getHostId()); + auditHost((HostVO) host); + } + } + } + return true; + } + + @Override + public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) { + return null; + } + + @Override + public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException { + + } + + @Override + public boolean processDisconnect(long agentId, Status state) { + return true; + } + + @Override + public boolean isRecurring() { + return false; + } + + @Override + public int getTimeout() { + return 0; + } + + @Override + public boolean processTimeout(long agentId, long seq) { + return true; + } + }, false, true, false); + } + + @DB + private void initNuageNetworkOffering() { + Transaction.execute(new TransactionCallbackNoReturn() { + @Override + public void doInTransactionWithoutResult(TransactionStatus status) { + if (_networkOfferingDao.findByUniqueName(nuageVspSharedNetworkOfferingWithSGServiceName) == null) { + NetworkOfferingVO defaultNuageVspSharedSGNetworkOffering = + new NetworkOfferingVO(nuageVspSharedNetworkOfferingWithSGServiceName, "Offering for NuageVsp Shared Security group enabled networks", + Networks.TrafficType.Guest, false, false, null, null, true, NetworkOffering.Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false); + + defaultNuageVspSharedSGNetworkOffering.setState(NetworkOffering.State.Enabled); + defaultNuageVspSharedSGNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultNuageVspSharedSGNetworkOffering); + + Map defaultNuageVspSharedSGNetworkOfferingProviders = new HashMap(); + defaultNuageVspSharedSGNetworkOfferingProviders.put(Network.Service.Dhcp, Network.Provider.NuageVsp); + defaultNuageVspSharedSGNetworkOfferingProviders.put(Network.Service.SecurityGroup, Network.Provider.NuageVsp); + defaultNuageVspSharedSGNetworkOfferingProviders.put(Network.Service.Connectivity, Network.Provider.NuageVsp); + + for (Network.Service service : defaultNuageVspSharedSGNetworkOfferingProviders.keySet()) { + NetworkOfferingServiceMapVO offService = + new NetworkOfferingServiceMapVO(defaultNuageVspSharedSGNetworkOffering.getId(), service, defaultNuageVspSharedSGNetworkOfferingProviders.get(service)); + _networkOfferingServiceMapDao.persist(offService); + s_logger.trace("Added service for the NuageVsp network offering: " + offService); + } + } + } + }); + } + + @DB + private void initNuageVspVpcOffering() { + //configure default Nuage VSP vpc offering + Transaction.execute(new TransactionCallbackNoReturn() { + @Override + public void doInTransactionWithoutResult(TransactionStatus status) { + if (_vpcOffDao.findByUniqueName(nuageVPCOfferingName) == null) { + s_logger.debug("Creating default Nuage VPC offering " + nuageVPCOfferingName); + + Map> svcProviderMap = new HashMap>(); + Set nuageProviders = new HashSet(); + nuageProviders.add(Network.Provider.NuageVsp); + svcProviderMap.put(Network.Service.Connectivity, nuageProviders); + svcProviderMap.put(Network.Service.Dhcp, nuageProviders); + svcProviderMap.put(Network.Service.StaticNat, nuageProviders); + svcProviderMap.put(Network.Service.SourceNat, nuageProviders); + svcProviderMap.put(Network.Service.NetworkACL, nuageProviders); + + Set userDataProviders = new HashSet(); + userDataProviders.add(Network.Provider.VPCVirtualRouter); --- End diff -- Replace lines 797-798 with a call to Collections.singleton(). --- 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. ---