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 06C2D18F2C for ; Wed, 14 Oct 2015 12:26:49 +0000 (UTC) Received: (qmail 16173 invoked by uid 500); 14 Oct 2015 12:26:32 -0000 Delivered-To: apmail-cloudstack-dev-archive@cloudstack.apache.org Received: (qmail 16111 invoked by uid 500); 14 Oct 2015 12:26:32 -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 16003 invoked by uid 99); 14 Oct 2015 12:26:31 -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; Wed, 14 Oct 2015 12:26:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 704DDE00BD; Wed, 14 Oct 2015 12:26:31 +0000 (UTC) From: nlivens 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: <20151014122631.704DDE00BD@git1-us-west.apache.org> Date: Wed, 14 Oct 2015 12:26:31 +0000 (UTC) Github user nlivens commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/801#discussion_r41986510 --- 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) { --- End diff -- Need to catch Exception because of Map clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();, which declares throws Exception --- 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. ---