Return-Path: X-Original-To: apmail-cloudstack-issues-archive@www.apache.org Delivered-To: apmail-cloudstack-issues-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3586182DB for ; Mon, 12 Oct 2015 21:33:05 +0000 (UTC) Received: (qmail 37395 invoked by uid 500); 12 Oct 2015 21:33:05 -0000 Delivered-To: apmail-cloudstack-issues-archive@cloudstack.apache.org Received: (qmail 37354 invoked by uid 500); 12 Oct 2015 21:33:05 -0000 Mailing-List: contact issues-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 issues@cloudstack.apache.org Received: (qmail 37344 invoked by uid 500); 12 Oct 2015 21:33:05 -0000 Delivered-To: apmail-incubator-cloudstack-issues@incubator.apache.org Received: (qmail 37341 invoked by uid 99); 12 Oct 2015 21:33:05 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Oct 2015 21:33:05 +0000 Date: Mon, 12 Oct 2015 21:33:05 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: cloudstack-issues@incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CLOUDSTACK-8832) Update Nuage VSP plugin to work with Nuage VSP release 3.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CLOUDSTACK-8832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14953777#comment-14953777 ] ASF GitHub Bot commented on CLOUDSTACK-8832: -------------------------------------------- Github user jburwell commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/801#discussion_r41803706 --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java --- @@ -152,50 +243,179 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) { throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network"); } - Map params = new HashMap(); - params.put("guid", UUID.randomUUID().toString()); - params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId())); - params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId())); - params.put("name", "Nuage VSD - " + cmd.getHostName()); - params.put("hostname", cmd.getHostName()); - params.put("cmsuser", cmd.getUserName()); - String cmsUserPasswordBase64 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes(Charset.forName("UTF-8")))); - params.put("cmsuserpass", cmsUserPasswordBase64); - int port = cmd.getPort(); - if (0 == port) { - port = 443; - } - params.put("port", String.valueOf(port)); - params.put("apirelativepath", "/nuage/api/" + cmd.getApiVersion()); - params.put("retrycount", String.valueOf(cmd.getApiRetryCount())); - params.put("retryinterval", String.valueOf(cmd.getApiRetryInterval())); + try { + NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(null, null, 1, 1, null); - Map hostdetails = new HashMap(); - hostdetails.putAll(params); + Map clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults(); + String apiVersion = MoreObjects.firstNonNull(cmd.getApiVersion(), (String) clientDefaults.get("CURRENT_API_VERSION")); + if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) { + throw new CloudRuntimeException("Unsupported API version : " + apiVersion); + } - try { + Map params = new HashMap(); + params.put("guid", UUID.randomUUID().toString()); + params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId())); + params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId())); + params.put("name", "Nuage VSD - " + cmd.getHostName()); + params.put("hostname", cmd.getHostName()); + params.put("cmsuser", cmd.getUserName()); + String cmsUserPasswordBase64 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes())); + params.put("cmsuserpass", cmsUserPasswordBase64); + int port = cmd.getPort(); + if (0 == port) { + port = 8443; + } + params.put("port", String.valueOf(port)); + params.put("apiversion", apiVersion); + params.put("apirelativepath", "/nuage/api/" + apiVersion); + params.put("retrycount", String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), clientDefaults.get("DEFAULT_API_RETRY_COUNT")))); + params.put("retryinterval", String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), clientDefaults.get("DEFAULT_API_RETRY_INTERVAL")))); + + final Map hostdetails = new HashMap(); + hostdetails.putAll(params); resource.configure(cmd.getHostName(), hostdetails); - final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params); + Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params); if (host != null) { - return Transaction.execute(new TransactionCallback() { - @Override - public NuageVspDeviceVO doInTransaction(TransactionStatus status) { - NuageVspDeviceVO nuageVspDevice = new NuageVspDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName); - _nuageVspDao.persist(nuageVspDevice); + 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); + + ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id"); + host = findNuageVspHost(nuageVspDevice.getHostId()); + SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null); + SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd); + if (answer != null && answer.getSuccess()) { + registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":" + answer.getNuageVspCmsId()); + + detail = new DetailVO(host.getId(), "nuagevspcmsid", answer.getNuageVspCmsId()); + _hostDetailsDao.persist(detail); + hostdetails.put("nuagevspcmsid", answer.getNuageVspCmsId()); + resource.configure((String) hostdetails.get("hostname"), hostdetails); + + auditDomainsOnVsp((HostVO) host, true, false); + } else { + throw new CloudRuntimeException("Failed to register CMS ID"); + } + return nuageVspDevice; + } else { + throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error."); + } + } catch (Exception e) { + throw new CloudRuntimeException(e); + } + } + + @Override + public NuageVspDeviceVO updateNuageVspDevice(UpdateNuageVspDeviceCmd command) { + ServerResource 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"); + } 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"); + } + + HostVO nuageVspHost = null; + NuageVspDeviceVO nuageVspDevice = null; + List nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId); + if (nuageVspDevices == null || nuageVspDevices.size() == 0) { + 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); + } + + Map paramsTobeUpdated = new HashMap(); + if (!Strings.isNullOrEmpty(command.getHostName()) && + !command.getHostName().equals(nuageVspHost.getDetails().get("hostname"))) { + paramsTobeUpdated.put("name", "Nuage VSD - " + command.getHostName()); + paramsTobeUpdated.put("hostname", command.getHostName()); + } + + if (!Strings.isNullOrEmpty(command.getUserName()) && + !command.getUserName().equals(nuageVspHost.getDetails().get("cmsuser"))) { + paramsTobeUpdated.put("cmsuser", command.getUserName()); + } + + if (!Strings.isNullOrEmpty(command.getPassword())) { + String encodedNewPassword = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(command.getPassword().getBytes())); + if (!encodedNewPassword.equals(nuageVspHost.getDetails().get("cmsuserpass"))) { + paramsTobeUpdated.put("cmsuserpass", org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(command.getPassword().getBytes()))); + } + } + + if (command.getPort() != null && + command.getPort() != Integer.parseInt(nuageVspHost.getDetails().get("port"))) { + paramsTobeUpdated.put("port", String.valueOf(command.getPort())); + } + + GetClientDefaultsCommand getClientDefaultsCmd = new GetClientDefaultsCommand(); + GetClientDefaultsAnswer getClientDefaultsAnswer = (GetClientDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), getClientDefaultsCmd); + String apiVersion = MoreObjects.firstNonNull(command.getApiVersion(), getClientDefaultsAnswer.getCurrentApiVersion()); + SupportedApiVersionCommand supportedApiVersionCmd = new SupportedApiVersionCommand(apiVersion); + SupportedApiVersionAnswer supportedApiVersionAnswer = (SupportedApiVersionAnswer) _agentMgr.easySend(nuageVspHost.getId(), supportedApiVersionCmd); + if (!supportedApiVersionAnswer.getResult()) { + throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + getClientDefaultsAnswer.getCurrentApiVersion()); + } + + String apiRelativePath = "/nuage/api/" + command.getApiVersion(); + if (!apiRelativePath.equals(nuageVspHost.getDetails().get("apirelativepath"))) { + paramsTobeUpdated.put("apirelativepath", apiRelativePath); + paramsTobeUpdated.put("apiversion", apiVersion); + } - DetailVO detail = new DetailVO(host.getId(), "nuagevspdeviceid", String.valueOf(nuageVspDevice.getId())); - _hostDetailsDao.persist(detail); + if (command.getApiRetryCount() != null && + command.getApiRetryCount() != Integer.parseInt(nuageVspHost.getDetails().get("retrycount"))) { + paramsTobeUpdated.put("retrycount", String.valueOf(command.getApiRetryCount())); + } + + if (command.getApiRetryInterval() != null && + command.getApiRetryInterval() != Integer.parseInt(nuageVspHost.getDetails().get("retryinterval"))) { --- End diff -- Extract the Integer parsing for a ``final`` local variable to make this ``if`` block easier to read/follow. > Update Nuage VSP plugin to work with Nuage VSP release 3.2 > ---------------------------------------------------------- > > Key: CLOUDSTACK-8832 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-8832 > Project: CloudStack > Issue Type: Improvement > Security Level: Public(Anyone can view this level - this is the default.) > Components: Management Server > Affects Versions: 4.6.0 > Reporter: Nick Livens > Assignee: Nick Livens > Attachments: nuageVspMarvinLogs.tar.gz > > > Nuage VSP 3.2 is being released, we want to bring the plugin up to date for this release -- This message was sent by Atlassian JIRA (v6.3.4#6332)