You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by nlivens <gi...@git.apache.org> on 2015/09/11 10:00:24 UTC

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

GitHub user nlivens opened a pull request:

    https://github.com/apache/cloudstack/pull/801

    CLOUDSTACK-8832 : Update Nuage VSP plugin to work with Nuage VSP rele…

    …ase 3.2

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/nlivens/cloudstack updated-nuage-vsp-plugin

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cloudstack/pull/801.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #801
    
----
commit 6602ccb6b13f2b77d70cd5a4448fc56eccd7bce1
Author: Nick Livens <ni...@nuagenetworks.net>
Date:   2015-09-11T07:57:13Z

    CLOUDSTACK-8832 : Update Nuage VSP plugin to work with Nuage VSP release 3.2

----


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43091944
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/PingNuageVspCommand.java ---
    @@ -17,18 +17,37 @@
     // under the License.
     //
     
    -package com.cloud.agent.api.element;
    +package com.cloud.agent.api;
     
    -import com.cloud.agent.api.Answer;
    +import com.cloud.host.Host;
     
    -public class ShutDownVpcVspAnswer extends Answer {
    +public class PingNuageVspCommand extends PingCommand {
     
    -    public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, boolean success, String details) {
    -        super(cmd, success, details);
    +    private final boolean shouldAudit;
    +
    +    public PingNuageVspCommand(Host.Type type, long id, boolean shouldAudit) {
    +        super(type, id);
    +        this.shouldAudit = shouldAudit;
         }
     
    -    public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, Exception e) {
    -        super(cmd, e);
    +    public boolean shouldAudit() {
    +        return shouldAudit;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    Added attributes from the <code>PingCommand</code> super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031964
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncVspCommand.java ---
    @@ -39,4 +39,21 @@ public String getNuageVspEntity() {
             return _nuageVspEntity;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This ``equals`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031150
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/ImplementNetworkVspCommand.java ---
    @@ -112,13 +147,212 @@ public boolean isDefaultEgressPolicy() {
             return _defaultEgressPolicy;
         }
     
    -    public Collection<String> getIpAddressRange() {
    +    public Collection<String[]> getIpAddressRange() {
             return _ipAddressRange;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ImplementNetworkVspCommand> {
    +        private String _networkDomainName;
    +        private String _networkDomainPath;
    +        private String _networkDomainUuid;
    +        private String _networkAccountName;
    +        private String _networkAccountUuid;
    +        private String _networkName;
    +        private String _networkCidr;
    +        private String _networkGateway;
    +        private Long _networkAclId;
    +        private List<String> _dnsServers;
    +        private List<String> _gatewaySystemIds;
    +        private String _networkUuid;
    +        private boolean _isL3Network;
    +        private boolean _isVpc;
    +        private boolean _isSharedNetwork;
    +        private String _vpcName;
    +        private String _vpcUuid;
    +        private boolean _defaultEgressPolicy;
    +        private List<String[]> _ipAddressRange;
    +        private String _domainTemplateName;
    +
    +        public Builder networkDomainName(String networkDomainName) {
    +            this._networkDomainName = networkDomainName;
    +            return this;
    +        }
    +
    +        public Builder networkDomainPath(String networkDomainPath) {
    +            this._networkDomainPath = networkDomainPath;
    +            return this;
    +        }
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkAccountName(String networkAccountName) {
    +            this._networkAccountName = networkAccountName;
    +            return this;
    +        }
    +
    +        public Builder networkAccountUuid(String networkAccountUuid) {
    +            this._networkAccountUuid = networkAccountUuid;
    +            return this;
    +        }
    +
    +        public Builder networkName(String networkName) {
    +            this._networkName = networkName;
    +            return this;
    +        }
    +
    +        public Builder networkCidr(String networkCidr) {
    +            this._networkCidr = networkCidr;
    +            return this;
    +        }
    +
    +        public Builder networkGateway(String networkGateway) {
    +            this._networkGateway = networkGateway;
    +            return this;
    +        }
    +
    +        public Builder networkAclId(Long networkAclId) {
    +            this._networkAclId = networkAclId;
    +            return this;
    +        }
    +
    +        public Builder dnsServers(List<String> dnsServers) {
    +            this._dnsServers = dnsServers;
    +            return this;
    +        }
    +
    +        public Builder gatewaySystemIds(List<String> gatewaySystemIds) {
    +            this._gatewaySystemIds = gatewaySystemIds;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isVpc(boolean isVpc) {
    +            this._isVpc = isVpc;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcName(String vpcName) {
    +            this._vpcName = vpcName;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder defaultEgressPolicy(boolean defaultEgressPolicy) {
    +            this._defaultEgressPolicy = defaultEgressPolicy;
    +            return this;
    +        }
    +
    +        public Builder ipAddressRange(List<String[]> ipAddressRange) {
    +            this._ipAddressRange = ipAddressRange;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public ImplementNetworkVspCommand build() {
    +            return new ImplementNetworkVspCommand(_networkDomainName, _networkDomainPath, _networkDomainUuid, _networkAccountName, _networkAccountUuid, _networkName,
    +                    _networkCidr, _networkGateway, _networkAclId, _dnsServers, _gatewaySystemIds, _networkUuid, _isL3Network, _isVpc, _isSharedNetwork, _vpcName, _vpcUuid,
    +                    _defaultEgressPolicy, _ipAddressRange, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This ``equals`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41806251
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -424,9 +449,10 @@ private Answer executeRequest(ApplyAclRuleVspCommand cmd) {
         private Answer executeRequest(ShutDownVpcVspCommand cmd) {
             try {
                 isNuageVspElementLoaded();
    -            _nuageVspElementClient.shutDownVpc(cmd.getDomainUuid(), cmd.getVpcUuid());
    +            _nuageVspElementClient.shutdownVpc(cmd.getDomainUuid(), cmd.getVpcUuid(), cmd.getDomainTemplateName());
                 return new ShutDownVpcVspAnswer(cmd, true, "Shutdown VPC " + cmd.getVpcUuid());
             } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
    --- End diff --
    
    Please add identifying information about Nuage VSP device to assist with operational debugging.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41775675
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ShutDownVpcVspAnswer.java ---
    @@ -31,4 +31,13 @@ public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, Exception e) {
             super(cmd, e);
         }
     
    +    @Override
    +    public boolean equals(Object obj) {
    +        return super.equals(obj);
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return super.hashCode();
    +    }
    --- End diff --
    
    Why does this class exist?  It adds no state or behavior to the ``Answer`` base class.  Why not simply use ``Answer`` in this circumstance?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41979391
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -303,13 +422,17 @@ protected boolean canHandle(Network network, Service service) {
             }
     
             if (!_networkModel.isProviderForNetwork(getProvider(), network.getId())) {
    -            s_logger.debug("NuageElement is not a provider for network " + network.getDisplayText());
    +            if (s_logger.isDebugEnabled()) {
    +                s_logger.debug("NuageElement is not a provider for network " + network.getDisplayText());
    --- End diff --
    
    Changed <code>NuageElement</code> to <code>NuageVsp</code> to reflect the name of the provider. No additional context information needed.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43091029
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +441,22 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
     
             if (allIPsInCidr.size() > 3) {
    +            //get the second IP and see if it the networks GatewayIP
                 Iterator<Long> ipIterator = allIPsInCidr.iterator();
                 long vip = ipIterator.next();
    --- End diff --
    
    Added your piece of code as extra validation for the returned Set.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43030869
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyStaticNatVspCommand.java ---
    @@ -51,13 +61,91 @@ public boolean isL3Network() {
             return _isL3Network;
         }
     
    +    public boolean isVpc() {
    +        return _isVpc;
    +    }
    +
         public List<Map<String, Object>> getStaticNatDetails() {
             return _staticNatDetails;
         }
     
    +    public static class Builder implements CmdBuilder<ApplyStaticNatVspCommand> {
    +        private String _networkDomainUuid;
    +        private String _networkUuid;
    +        private String _vpcOrSubnetUuid;
    +        private boolean _isL3Network;
    +        private boolean _isVpc;
    +        private List<Map<String, Object>> _staticNatDetails;
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
    +            this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isVpc(boolean isVpc) {
    +            this._isVpc = isVpc;
    +            return this;
    +        }
    +
    +        public Builder staticNatDetails(List<Map<String, Object>> staticNatDetails) {
    +            this._staticNatDetails = staticNatDetails;
    +            return this;
    +        }
    +
    +        @Override
    +        public ApplyStaticNatVspCommand build() {
    +            return new ApplyStaticNatVspCommand(_networkDomainUuid, _networkUuid, _vpcOrSubnetUuid, _isL3Network, _isVpc, _staticNatDetails);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ApplyStaticNatVspCommand that = (ApplyStaticNatVspCommand) o;
    +
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isVpc != that._isVpc) return false;
    +        if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
    +            return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_staticNatDetails != null ? !_staticNatDetails.equals(that._staticNatDetails) : that._staticNatDetails != null)
    +            return false;
    +        if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    This ``hashCode`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39898685
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -129,6 +145,18 @@
         AgentManager _agentMgr;
         @Inject
         NetworkOfferingDao _ntwkOfferingDao;
    +    @Inject
    +    ConfigurationDao _configDao;
    +    @Inject
    +    NuageVspManager _nuageVspManager;
    +    @Inject
    +    FirewallRulesDao _firewallRulesDao;
    +    @Inject
    +    FirewallRulesCidrsDao _firewallRulesCidrsDao;
    +    @Inject
    +    PhysicalNetworkDao _physicalNetworkDao;
    +    @Inject
    +    NetworkACLItemDao _networkACLItemDao;
     
         @Override
         public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> service) throws ResourceUnavailableException {
    --- End diff --
    
    This method is incredibly long and performing many different operations.  Decompose into a smaller private/utility methods and possibly consider some small ValueObjects.  Each of these methods should have a set of unit tests to verify them.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39895754
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/ReserveVmInterfaceVspCommand.java ---
    @@ -36,14 +37,26 @@
         String _vmUuid;
         String _vmUserName;
         String _vmUserDomainName;
    -
    -    public ReserveVmInterfaceVspCommand(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, String vpcUuid, String networkDomainUuid,
    -            String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid, String vmUserName, String vmUserDomainName) {
    +    boolean _useStaticIp;
    +    String _staticIp;
    +    String _staticNatIpUuid;
    +    String _staticNatIpAddress;
    +    boolean _isStaticNatIpAllocated;
    +    boolean _isOneToOneNat;
    +    String _staticNatVlanUuid;
    +    String _staticNatVlanGateway;
    +    String _staticNatVlanNetmask;
    +
    +    public ReserveVmInterfaceVspCommand(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String networkDomainUuid,
    +            String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid, String vmUserName, String vmUserDomainName,
    +            boolean useStaticIp, String staticIp, String staticNatIpUuid, String staticNatIpAddress, boolean isStaticNatIpAllocated, boolean isOneToOneNat, String staticNatVlanUuid,
    +            String staticNatVlanGateway, String staticNatVlanNetmask) {
    --- End diff --
    
    The number of parameters is extremely large -- creating a brittle interface and difficult to comprehend client client. Please refactor to the Builder pattern.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39896513
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncNuageVspCmsIdCommand.java ---
    @@ -17,38 +17,33 @@
     // under the License.
     //
     
    -package com.cloud.agent.api.guru;
    +package com.cloud.agent.api.sync;
     
     import com.cloud.agent.api.Command;
     
    -public class ReleaseVmVspCommand extends Command {
    +public class SyncNuageVspCmsIdCommand extends Command {
    --- End diff --
    
    Per Java best practice, this class should implement the equals(Object), hashCode(), and toString() methods.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807713
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspElementClient.java ---
    @@ -24,13 +24,18 @@
     
     public interface NuageVspElementClient {
     
    -    public void applyStaticNats(String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> staticNatDetails) throws Exception;
    +    boolean implement(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
    +                             boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
    +                             List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) throws Exception;
     
    -    public void applyAclRules(String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> aclRules, boolean isVpc, long networkId)
    -            throws Exception;
    +    void applyStaticNats(String networkDomainUuid, String networkUuid, String vpcOrSubnetUuid, boolean isL3Network, boolean isVpc,
    +                                List<Map<String, Object>> staticNatDetails) throws Exception;
     
    -    public void shutDownVpc(String domainUuid, String vpcUuid) throws Exception;
    +    void applyAclRules(boolean isNetworkAcl, String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, String networkName, boolean isL2Network,
    +                              List<Map<String, Object>> rules, long networkId, boolean egressDefaultPolicy, Boolean isAcsIngressAcl, boolean networkReset, String domainTemplateName) throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41990144
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspApiClient.java ---
    @@ -21,10 +21,10 @@
     
     public interface NuageVspApiClient {
     
    -    public void login() throws Exception;
    +    void login() throws Exception;
     
    -    public void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval);
    +    void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval, String nuageVspCmsId);
     
    -    public String executeRestApi(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
    -            String proxyUserDomainuuid) throws Exception;
    +    String executeRestApi(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
    +                                 String proxyUserDomainuuid) throws Exception;
    --- End diff --
    
    This is how the methods are declared in our client. They need to have the same signature as defined in our client.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41973409
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncNuageVspCmsIdAnswer.java ---
    @@ -0,0 +1,71 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Answer;
    +
    +public class SyncNuageVspCmsIdAnswer extends Answer {
    +
    +    private final boolean _success;
    +    private final String _nuageVspCmsId;
    +    private final SyncNuageVspCmsIdCommand.SyncType _syncType;
    +
    +    public SyncNuageVspCmsIdAnswer(boolean success, String nuageVspCmsId, SyncNuageVspCmsIdCommand.SyncType syncType) {
    +        super();
    +        this._success = success;
    +        this._nuageVspCmsId = nuageVspCmsId;
    +        this._syncType = syncType;
    +    }
    +
    +    public boolean getSuccess() {
    +        return _success;
    +    }
    +
    +    public String getNuageVspCmsId() {
    +        return _nuageVspCmsId;
    +    }
    +
    +    public SyncNuageVspCmsIdCommand.SyncType getSyncType() {
    +        return _syncType;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncNuageVspCmsIdAnswer that = (SyncNuageVspCmsIdAnswer) o;
    +
    +        if (_success != that._success) return false;
    +        if (_nuageVspCmsId != null ? !_nuageVspCmsId.equals(that._nuageVspCmsId) : that._nuageVspCmsId != null)
    +            return false;
    +        if (_syncType != that._syncType) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = (_success ? 1 : 0);
    +        result = 31 * result + (_nuageVspCmsId != null ? _nuageVspCmsId.hashCode() : 0);
    +        result = 31 * result + (_syncType != null ? _syncType.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code> of which <code>Answer</code> is a subclass


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39895038
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/UpdateNuageVspDeviceCommand.java ---
    @@ -0,0 +1,42 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api;
    +
    +import java.util.Map;
    +
    +public class UpdateNuageVspDeviceCommand extends Command {
    +
    +    Map<String, String> _parametersToBeUpdated;
    +
    +    public UpdateNuageVspDeviceCommand(Map<String, String> parametersToBeUpdated) {
    +        super();
    +        this._parametersToBeUpdated = parametersToBeUpdated;
    +    }
    +
    +    public Map<String, String> getParametersToBeUpdated() {
    +        return _parametersToBeUpdated;
    --- End diff --
    
    A defensive copy or the value wrapped in a call to  ``Collections.unmodifiableMap(...)``should be returned here in order to avoid unintended side effects by users of the return value.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43091160
  
    --- 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];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            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<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (StringUtils.isNotBlank(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(tokens.countTokens());
    +            while (tokens.hasMoreTokens())
    +            {
    +                gatewayIds.add(tokens.nextToken());
    +            }
    --- End diff --
    
    Implemented as suggested.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031179
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/ImplementNetworkVspCommand.java ---
    @@ -112,13 +147,212 @@ public boolean isDefaultEgressPolicy() {
             return _defaultEgressPolicy;
         }
     
    -    public Collection<String> getIpAddressRange() {
    +    public Collection<String[]> getIpAddressRange() {
             return _ipAddressRange;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ImplementNetworkVspCommand> {
    +        private String _networkDomainName;
    +        private String _networkDomainPath;
    +        private String _networkDomainUuid;
    +        private String _networkAccountName;
    +        private String _networkAccountUuid;
    +        private String _networkName;
    +        private String _networkCidr;
    +        private String _networkGateway;
    +        private Long _networkAclId;
    +        private List<String> _dnsServers;
    +        private List<String> _gatewaySystemIds;
    +        private String _networkUuid;
    +        private boolean _isL3Network;
    +        private boolean _isVpc;
    +        private boolean _isSharedNetwork;
    +        private String _vpcName;
    +        private String _vpcUuid;
    +        private boolean _defaultEgressPolicy;
    +        private List<String[]> _ipAddressRange;
    +        private String _domainTemplateName;
    +
    +        public Builder networkDomainName(String networkDomainName) {
    +            this._networkDomainName = networkDomainName;
    +            return this;
    +        }
    +
    +        public Builder networkDomainPath(String networkDomainPath) {
    +            this._networkDomainPath = networkDomainPath;
    +            return this;
    +        }
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkAccountName(String networkAccountName) {
    +            this._networkAccountName = networkAccountName;
    +            return this;
    +        }
    +
    +        public Builder networkAccountUuid(String networkAccountUuid) {
    +            this._networkAccountUuid = networkAccountUuid;
    +            return this;
    +        }
    +
    +        public Builder networkName(String networkName) {
    +            this._networkName = networkName;
    +            return this;
    +        }
    +
    +        public Builder networkCidr(String networkCidr) {
    +            this._networkCidr = networkCidr;
    +            return this;
    +        }
    +
    +        public Builder networkGateway(String networkGateway) {
    +            this._networkGateway = networkGateway;
    +            return this;
    +        }
    +
    +        public Builder networkAclId(Long networkAclId) {
    +            this._networkAclId = networkAclId;
    +            return this;
    +        }
    +
    +        public Builder dnsServers(List<String> dnsServers) {
    +            this._dnsServers = dnsServers;
    +            return this;
    +        }
    +
    +        public Builder gatewaySystemIds(List<String> gatewaySystemIds) {
    +            this._gatewaySystemIds = gatewaySystemIds;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isVpc(boolean isVpc) {
    +            this._isVpc = isVpc;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcName(String vpcName) {
    +            this._vpcName = vpcName;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder defaultEgressPolicy(boolean defaultEgressPolicy) {
    +            this._defaultEgressPolicy = defaultEgressPolicy;
    +            return this;
    +        }
    +
    +        public Builder ipAddressRange(List<String[]> ipAddressRange) {
    +            this._ipAddressRange = ipAddressRange;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public ImplementNetworkVspCommand build() {
    +            return new ImplementNetworkVspCommand(_networkDomainName, _networkDomainPath, _networkDomainUuid, _networkAccountName, _networkAccountUuid, _networkName,
    +                    _networkCidr, _networkGateway, _networkAclId, _dnsServers, _gatewaySystemIds, _networkUuid, _isL3Network, _isVpc, _isSharedNetwork, _vpcName, _vpcUuid,
    +                    _defaultEgressPolicy, _ipAddressRange, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ImplementNetworkVspCommand that = (ImplementNetworkVspCommand) o;
    +
    +        if (_defaultEgressPolicy != that._defaultEgressPolicy) return false;
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isSharedNetwork != that._isSharedNetwork) return false;
    +        if (_isVpc != that._isVpc) return false;
    +        if (_dnsServers != null ? !_dnsServers.equals(that._dnsServers) : that._dnsServers != null) return false;
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_gatewaySystemIds != null ? !_gatewaySystemIds.equals(that._gatewaySystemIds) : that._gatewaySystemIds != null)
    +            return false;
    +        if (_ipAddressRange != null ? !_ipAddressRange.equals(that._ipAddressRange) : that._ipAddressRange != null)
    +            return false;
    +        if (_networkAccountName != null ? !_networkAccountName.equals(that._networkAccountName) : that._networkAccountName != null)
    +            return false;
    +        if (_networkAccountUuid != null ? !_networkAccountUuid.equals(that._networkAccountUuid) : that._networkAccountUuid != null)
    +            return false;
    +        if (_networkAclId != null ? !_networkAclId.equals(that._networkAclId) : that._networkAclId != null)
    +            return false;
    +        if (_networkCidr != null ? !_networkCidr.equals(that._networkCidr) : that._networkCidr != null) return false;
    +        if (_networkDomainName != null ? !_networkDomainName.equals(that._networkDomainName) : that._networkDomainName != null)
    +            return false;
    +        if (_networkDomainPath != null ? !_networkDomainPath.equals(that._networkDomainPath) : that._networkDomainPath != null)
    +            return false;
    +        if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
    +            return false;
    +        if (_networkGateway != null ? !_networkGateway.equals(that._networkGateway) : that._networkGateway != null)
    +            return false;
    +        if (_networkName != null ? !_networkName.equals(that._networkName) : that._networkName != null) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_vpcName != null ? !_vpcName.equals(that._vpcName) : that._vpcName != null) return false;
    +        if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    This ``hashCode`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41778375
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -205,6 +250,75 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
                 return false;
             }
     
    +        final boolean egressDefaultPolicy = offering.getEgressDefaultPolicy();
    +        Domain networkDomain = _domainDao.findById(network.getDomainId());
    +        boolean isFirewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.Firewall);
    +        List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +
    +        boolean isL2Network = false, isL3Network = false, isShared = false;
    +        String subnetUuid = network.getUuid();
    +        if (offering.getGuestType() == Network.GuestType.Shared) {
    +            isShared = true;
    +            subnetUuid = networkDomain.getUuid();
    +        } else if (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.StaticNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
    +            isL3Network = true;
    +        } else {
    +            isL2Network = true;
    +        }
    +
    +        String preConfiguredDomainTemplateName = getPreConfiguredDomainTemplateName(network, offering);
    +        List<FirewallRuleVO> firewallIngressRulesToApply =
    +                _firewallRulesDao.listByNetworkPurposeTrafficType(network.getId(), FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress);
    +        for (FirewallRuleVO rule : firewallIngressRulesToApply) {
    +            // load cidrs if any
    +            rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId()));
    +        }
    +
    +        List<FirewallRuleVO> firewallEgressRulesToApply =
    +                _firewallRulesDao.listByNetworkPurposeTrafficType(network.getId(), FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress);
    +        for (FirewallRuleVO rule : firewallEgressRulesToApply) {
    +            // load cidrs if any
    +            rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId()));
    +        }
    +
    +        List<Map<String, Object>> ingressFirewallRules = Lists.transform(firewallIngressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<Map<String, Object>> egressFirewallRules = Lists.transform(firewallEgressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    --- End diff --
    
    What is the status of addressing this comment?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39899741
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -454,6 +563,80 @@ protected boolean applyACLRules(Network network, List<? extends InternalIdentity
         }
     
         @Override
    +    public boolean applyNetworkACLs(Network config, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
    +        if (rules == null || rules.isEmpty()) {
    +            s_logger.debug("No rules to apply. So, delete all the existing ACL in VSP from Subnet with uuid " + config.getUuid());
    +        } else {
    +            s_logger.debug("New rules has to applied. So, delete all the existing ACL in VSP from Subnet with uuid " + config.getUuid());
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43043241
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -483,7 +663,7 @@ protected HostVO getNuageVspHost(Long physicalNetworkId) throws CloudException {
                 nuageVspHost = _hostDao.findById(config.getHostId());
                 _hostDao.loadDetails(nuageVspHost);
             } else {
    -            throw new CloudException("Nuage VSD is not configured on physical network " + physicalNetworkId);
    +            throw new CloudRuntimeException("Nuage VSD is not configured on physical network " + physicalNetworkId);
    --- End diff --
    
    Please add identifying about the Nuage VSP device that failed.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41986636
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    +        if (nuageVspDevices == null || nuageVspDevices.size() == 0) {
    --- End diff --
    
    Used <code>nuageVspDevices.isEmpty()</code>.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776309
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/DeallocateVmVspAnswer.java ---
    @@ -31,4 +31,14 @@ public DeallocateVmVspAnswer(Command command, Exception e) {
         public DeallocateVmVspAnswer(DeallocateVmVspCommand cmd, boolean success, String details) {
             super(cmd, success, details);
         }
    +
    +    @Override
    +    public boolean equals(Object obj) {
    +        return super.equals(obj);
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return super.hashCode();
    +    }
    --- End diff --
    
    Why does this class exist?  It adds no state or behavior to the ``Answer`` base class.  Why not simply use ``Answer`` in this circumstance?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807696
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspElementClient.java ---
    @@ -24,13 +24,18 @@
     
     public interface NuageVspElementClient {
     
    -    public void applyStaticNats(String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> staticNatDetails) throws Exception;
    +    boolean implement(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
    +                             boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
    +                             List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-157683273
  
    Awesome! Thanks @jburwell for the thorough review, thanks @remibergsma for merging it in, thanks to all who helped getting this PR in! Much appreciated! :)


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39899186
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -395,31 +510,23 @@ public IpDeployer getIpDeployer(Network network) {
     
         @Override
         public boolean applyFWRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
    -        s_logger.debug("Handling applyFWRules for network " + network.getName() + " with " + rules.size() + " FWRules");
    -        if (rules != null && rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
    +        if (rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
    --- End diff --
    
    Check that ``rules`` is not null and respond accordingly (e.g. throw an InvalidParameterException).


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776980
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/StartupVspCommand.java ---
    @@ -26,4 +26,14 @@
         public StartupVspCommand() {
             super(Host.Type.L2Networking);
         }
    +
    +    @Override
    +    public boolean equals(Object obj) {
    +        return super.equals(obj);
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return super.hashCode();
    +    }
    --- End diff --
    
    Please implement ``toString()`` to provide debugging state information for debugging purposes.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-154200225
  
    :+1:  LGTM
    
    @nlivens excellent work -- much appreciate the hard work.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41988188
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -285,60 +525,345 @@ 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 (!Strings.isNullOrEmpty(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!");
    --- End diff --
    
    Changed log level to <code>ERROR</code>. No reason for it to be <code>FATAL</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-153418530
  
    @KrisSterckx it not a matter of trust.  By contributing this code to our community, we are responsible for its long-term support and maintenance.  Therefore, we must be able to independently verify the plugin's operation.  Before I am comfortable approving this PR, we must be able to verify the proper operation of this plugin.  


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39902120
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -201,51 +234,82 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil
         @Override
         public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
                 throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    -        nic.setBroadcastUri(network.getBroadcastUri());
    -        nic.setIsolationUri(network.getBroadcastUri());
    -
    -        s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    -        DataCenter dc = _dcDao.findById(network.getDataCenterId());
    -        Account networksAccount = _accountDao.findById(network.getAccountId());
    -        DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        long networkOwnedBy = network.getAccountId();
    -        AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    -        if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
             }
     
    -        //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    -        //that we create in VSP
    -        NicVO nicFrmDB = _nicDao.findById(nic.getId());
    -        long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
    -        boolean isL3Network = isL3Network(networkOfferingId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    -        }
    -        HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -        ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(nicFrmDB.getUuid(), nic.getMacAddress(), network.getUuid(), isL3Network, vpcUuid,
    -                networksDomain.getUuid(), networksAccount.getUuid(), vm.getType().equals(VirtualMachine.Type.DomainRouter), network.getBroadcastUri().getPath().substring(1),
    -                vm.getInstanceName(), vm.getUuid(), networksDomain.getUuid(), networksAccount.getUuid());
    -        ReserveVmInterfaceVspAnswer answer = (ReserveVmInterfaceVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ReserveVmInterfaceNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +        try {
    +            nic.setBroadcastUri(network.getBroadcastUri());
    +            nic.setIsolationUri(network.getBroadcastUri());
    +
    +            s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    +            DataCenter dc = _dcDao.findById(network.getDataCenterId());
    +            Account networksAccount = _accountDao.findById(network.getAccountId());
    +            DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            long networkOwnedBy = network.getAccountId();
    +            AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    +            if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +            }
    +
    +            //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    +            //that we create in VSP
    +            NicVO nicFrmDB = _nicDao.findById(nic.getId());
    +            NetworkOffering networkOffering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
    +            boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter);
    +            String domainRouterIp = network.getBroadcastUri().getPath().substring(1);
    --- End diff --
    
    What is the path has a trailing / character?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39901746
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -201,51 +234,82 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil
         @Override
         public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
                 throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    -        nic.setBroadcastUri(network.getBroadcastUri());
    -        nic.setIsolationUri(network.getBroadcastUri());
    -
    -        s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    -        DataCenter dc = _dcDao.findById(network.getDataCenterId());
    -        Account networksAccount = _accountDao.findById(network.getAccountId());
    -        DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        long networkOwnedBy = network.getAccountId();
    -        AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    -        if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41984914
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +442,28 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
     
             if (allIPsInCidr.size() > 3) {
    +            //get the second IP and see if it the networks GatewayIP
                 Iterator<Long> ipIterator = allIPsInCidr.iterator();
                 long vip = ipIterator.next();
                 if (NetUtils.ip2Long(network.getGateway()) == vip) {
    -                s_logger.debug("Gateway of the Network(" + network.getUuid() + ") has the first IP " + NetUtils.long2Ip(vip));
    +                if (s_logger.isDebugEnabled()) {
    +                    s_logger.debug("Gateway of the Network(" + network.getName() + ") has the first IP " + NetUtils.long2Ip(vip));
    +                }
                     vip = ipIterator.next();
                     virtualRouterIp = NetUtils.long2Ip(vip);
    -                s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getUuid() + ")");
    +                if (s_logger.isDebugEnabled()) {
    +                    s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getName() + ")");
    --- End diff --
    
    Changed the latter message to contain the previous one.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39895992
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java ---
    @@ -0,0 +1,54 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Answer;
    +
    +import java.util.Map;
    +
    +public class GetClientDefaultsAnswer extends Answer {
    +
    +    String _currentApiVersion;
    +    Integer _apiRetryCount;
    +    Long _apiRetryInterval;
    --- End diff --
    
    Why aren't these attributes declared ``private``?  Also, they are not modified outside of the constructor.  Why aren't they declared ``final`` as well?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41987747
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        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"))) {
    +            paramsTobeUpdated.put("retryinterval", String.valueOf(command.getApiRetryInterval()));
    +        }
     
    -                        return nuageVspDevice;
    +        if (!paramsTobeUpdated.isEmpty()) {
    +            Map<String, String> latestParamsValue = new HashMap<String, String>();
    +            latestParamsValue.putAll(nuageVspHost.getDetails());
    +            latestParamsValue.putAll(paramsTobeUpdated);
    +            Map<String, Object> hostdetails = new HashMap<String, Object>(latestParamsValue);
    +
    +            try {
    +                resource.configure("", hostdetails);
    +                UpdateNuageVspDeviceCommand cmd = new UpdateNuageVspDeviceCommand(latestParamsValue);
    +                UpdateNuageVspDeviceAnswer answer = (UpdateNuageVspDeviceAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +                if (answer == null || !answer.getResult()) {
    +                    s_logger.error("UpdateNuageVspDeviceCommand failed");
    --- End diff --
    
    Added some context and the parameters to the log statement.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by remibergsma <gi...@git.apache.org>.
Github user remibergsma commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-153287597
  
    @jburwell That's fine, although this branch can be rebased easily. I would do that before running tests anyway. But I'll focus on 4.6 first, so it makes sense to hold it now. Shouldn't take long.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39899765
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -454,6 +563,80 @@ protected boolean applyACLRules(Network network, List<? extends InternalIdentity
         }
     
         @Override
    +    public boolean applyNetworkACLs(Network config, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
    +        if (rules == null || rules.isEmpty()) {
    +            s_logger.debug("No rules to apply. So, delete all the existing ACL in VSP from Subnet with uuid " + config.getUuid());
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39899929
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -454,6 +563,80 @@ protected boolean applyACLRules(Network network, List<? extends InternalIdentity
         }
     
         @Override
    +    public boolean applyNetworkACLs(Network config, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
    --- End diff --
    
    This method never appears to return ``false``.  Why not declare it with as a ``void`` return type.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39896732
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/UpdateNuageVspDeviceCmd.java ---
    @@ -0,0 +1,180 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.api.commands;
    +
    +import com.cloud.api.response.NuageVspDeviceResponse;
    +import com.cloud.event.EventTypes;
    +import com.cloud.exception.ConcurrentOperationException;
    +import com.cloud.exception.InsufficientCapacityException;
    +import com.cloud.exception.InvalidParameterValueException;
    +import com.cloud.exception.ResourceAllocationException;
    +import com.cloud.exception.ResourceUnavailableException;
    +import com.cloud.network.NuageVspDeviceVO;
    +import com.cloud.network.manager.NuageVspManager;
    +import com.cloud.utils.exception.CloudRuntimeException;
    +import org.apache.cloudstack.api.APICommand;
    +import org.apache.cloudstack.api.ApiConstants;
    +import org.apache.cloudstack.api.ApiErrorCode;
    +import org.apache.cloudstack.api.BaseAsyncCmd;
    +import org.apache.cloudstack.api.BaseCmd;
    +import org.apache.cloudstack.api.Parameter;
    +import org.apache.cloudstack.api.ServerApiException;
    +import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
    +import org.apache.cloudstack.context.CallContext;
    +import org.apache.log4j.Logger;
    +
    +import javax.inject.Inject;
    +
    +@APICommand(name = "updateNuageVspDevice", responseObject = NuageVspDeviceResponse.class, description = "Update a Nuage VSP device")
    --- End diff --
    
    The since attribute should be declared on all APICommands for clearer documentation.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41981224
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -114,7 +117,9 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
             PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
             DataCenter dc = _dcDao.findById(plan.getDataCenterId());
             if (!canHandle(offering, dc.getNetworkType(), physnet)) {
    -            s_logger.debug("Refusing to design this network");
    +            if (s_logger.isDebugEnabled()) {
    +                s_logger.debug("Refusing to design this network");
    --- End diff --
    
    This is <code>DEBUG</code> logging since core ACS asks our plugin to design some network which we do not support, therefore we just log that we are refusing it, and just returning <code>NULL</code> which core ACS will handle nicely. Added some additional info about the network to be designed.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41777414
  
    --- Diff: plugins/network-elements/nuage-vsp/pom.xml ---
    @@ -28,6 +28,13 @@
         <version>4.6.0-SNAPSHOT</version>
         <relativePath>../../pom.xml</relativePath>
       </parent>
    +  <dependencies>
    +    <dependency>
    +      <groupId>org.apache.commons</groupId>
    +      <artifactId>commons-lang3</artifactId>
    +      <version>${cs.lang3.version}</version>
    +    </dependency>
    +  </dependencies>
    --- End diff --
    
    Is ``commons-lang3`` required by the nuage client jar?  If not, please use the equivalent facilities in Guava as that is the project's standard, common utility library.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41806385
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -441,6 +456,44 @@ private Answer executeRequest(SyncVspCommand cmd) {
             }
         }
     
    +    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
    +                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
    +                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    +            } else if (cmd.getSyncType() == SyncType.REGISTER) {
    +                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
    +                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
    +            } else {
    +                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
    +                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
    +            }
    +        } catch (Exception e) {
    +            return new SyncNuageVspCmsIdAnswer(false, null, cmd.getSyncType());
    +        }
    +    }
    +
    +    private Answer executeRequest(SyncDomainCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomainUuid(), cmd.getDomainName(), cmd.getDomainPath(), cmd.isToAdd(), cmd.isToRemove());
    +            return new SyncDomainAnswer(success);
    +        } catch (Exception e) {
    +            return new SyncDomainAnswer(false);
    +        }
    +    }
    +
    +    private Answer executeRequest(GetClientDefaultsCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            Map<String, Object> clientDefaults = _nuageVspManagerClient.getClientDefaults();
    +            return new GetClientDefaultsAnswer(cmd, clientDefaults);
    +        } catch (Exception e) {
    --- End diff --
    
    Why are all unchecked and checked exceptions being caught? It seems like we should only be catching the expected checked exceptions, and allow unchecked exceptions simply bubble out.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by KrisSterckx <gi...@git.apache.org>.
Github user KrisSterckx commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-150258402
  
    @remibergsma  how can we continue pls ? Could you run Travis again ? Can we do anything ? Thanks


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39958866
  
    --- Diff: plugins/network-elements/nuage-vsp/pom.xml ---
    @@ -28,6 +28,13 @@
         <version>4.6.0-SNAPSHOT</version>
         <relativePath>../../pom.xml</relativePath>
       </parent>
    +  <dependencies>
    +    <dependency>
    +      <groupId>org.apache.commons</groupId>
    +      <artifactId>commons-lang3</artifactId>
    +      <version>3.1</version>
    --- End diff --
    
    This dependency has been added since one of the methods of our private client returns an object of type Pair which is inside the commons-lang3 library


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41773461
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/NuageVspPluginClientLoader.java ---
    @@ -19,28 +19,86 @@
     
     package net.nuage.vsp.acs;
     
    +import net.nuage.vsp.acs.client.NuageVspApiClient;
    +import net.nuage.vsp.acs.client.NuageVspElementClient;
    +import net.nuage.vsp.acs.client.NuageVspGuruClient;
    +import net.nuage.vsp.acs.client.NuageVspManagerClient;
    +import net.nuage.vsp.acs.client.NuageVspSyncClient;
    +
     import java.net.MalformedURLException;
     import java.net.URL;
     import java.net.URLClassLoader;
     
     public class NuageVspPluginClientLoader {
     
    -    private static NuageVspPluginClientLoader nuageVspPluginClientClassloader;
    -    private ClassLoader loader = null;
    +    private ClassLoader _loader = null;
    +
    +    private NuageVspApiClient _nuageVspApiClient;
    +    private NuageVspElementClient _nuageVspElementClient;
    +    private NuageVspGuruClient _nuageVspGuruClient;
    +    private NuageVspManagerClient _nuageVspManagerClient;
    +    private NuageVspSyncClient _nuageVspSyncClient;
    +
    +    public static final String NUAGE_PLUGIN_CLIENT_JAR_FILE = "/usr/share/nuagevsp/lib/nuage-vsp-acs-client.jar";
    --- End diff --
    
    Seems the location of the client jar should be configurable.  I am also concerned that we are included a plugin into the open source project that has an implicit requirement for a non open source library.  The expectation is that any plugin built in the open source release has all dependencies to run included in the build.  I will open a discussion on the mailing list to discuss further.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41980395
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -205,9 +254,79 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
                 return false;
             }
     
    +        final boolean egressDefaultPolicy = offering.getEgressDefaultPolicy();
    +        Domain networkDomain = _domainDao.findById(network.getDomainId());
    +        boolean isFirewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.Firewall);
    +        List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +
    +        boolean isL2Network = false, isL3Network = false, isShared = false;
    +        String subnetUuid = network.getUuid();
    +        if (offering.getGuestType() == Network.GuestType.Shared) {
    +            isShared = true;
    +            subnetUuid = networkDomain.getUuid();
    +        } else if (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.StaticNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
    +            isL3Network = true;
    +        } else {
    +            isL2Network = true;
    +        }
    +
    +        String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
    +        List<FirewallRuleVO> firewallIngressRulesToApply = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Ingress);
    +        List<FirewallRuleVO> firewallEgressRulesToApply = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Egress);
    +
    +        List<Map<String, Object>> ingressFirewallRules = Lists.transform(firewallIngressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<Map<String, Object>> egressFirewallRules = Lists.transform(firewallEgressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
    +        List<String> acsFipUuid = new ArrayList<String>();
    +        for (IPAddressVO ip : ips) {
    +            acsFipUuid.add(ip.getUuid());
    +        }
    +
    +        try {
    +            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    +            ImplementVspCommand.Builder cmdBuilder = new ImplementVspCommand.Builder().networkId(network.getId()).networkDomainUuid(networkDomain.getUuid())
    +                    .networkUuid(network.getUuid()).networkName(network.getName()).vpcOrSubnetUuid(subnetUuid).isL2Network(isL2Network).isL3Network(isL3Network)
    +                    .isVpc(false).isShared(isShared).domainTemplateName(preConfiguredDomainTemplateName).isFirewallServiceSupported(isFirewallServiceSupported)
    +                    .dnsServers(dnsServers).ingressFirewallRules(ingressFirewallRules).egressFirewallRules(egressFirewallRules).acsFipUuid(acsFipUuid)
    +                    .egressDefaultPolicy(egressDefaultPolicy);
    +            ImplementVspAnswer answer = (ImplementVspAnswer) _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
    +            if (answer == null || !answer.getResult()) {
    +                s_logger.error("ImplementVspCommand for network " + network.getUuid() + " failed");
    +                if ((null != answer) && (null != answer.getDetails())) {
    +                    throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
    +                }
    +            }
    +        } catch (Exception e) {
    --- End diff --
    
    Removed the <code>try {} catch () {}</code> block since it didn't add any value


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41803394
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    +        if (nuageVspDevices == null || nuageVspDevices.size() == 0) {
    +            throw new CloudRuntimeException("Nuage VSD is not configured on physical network " + physicalNetworkId);
    +        } else {
    --- End diff --
    
    ``else`` is unnecessary as the ``throw`` will stop execution of the method.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43104314
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -112,8 +111,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
                 throw new ConfigurationException("Unable to find zone");
             }
     
    -        String hostname = (String)params.get("hostname");
    -        if (hostname == null) {
    +        _hostName = (String)params.get("hostname");
    +        if (_hostName == null) {
    --- End diff --
    
    Yes, changed for other fields which should not be empty as well.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39907736
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspElementClient.java ---
    @@ -24,12 +24,17 @@
     
     public interface NuageVspElementClient {
     
    -    public void applyStaticNats(String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> staticNatDetails) throws Exception;
    +    public boolean implement(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
    +                             boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
    +                             List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) throws Exception;
     
    -    public void applyAclRules(String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> aclRules, boolean isVpc, long networkId)
    -            throws Exception;
    +    public void applyStaticNats(String networkDomainUuid, String networkUuid, String vpcOrSubnetUuid, boolean isL3Network, boolean isVpc,
    +                                List<Map<String, Object>> staticNatDetails) throws Exception;
     
    -    public void shutDownVpc(String domainUuid, String vpcUuid) throws Exception;
    +    public void applyAclRules(boolean isNetworkAcl, String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, String networkName, boolean isL2Network,
    +                              List<Map<String, Object>> rules, long networkId, boolean egressDefaultPolicy, Boolean isAcsIngressAcl, boolean networkReset, String domainTemplateName) throws Exception;
    +
    +    public void shutdownVpc(String domainUuid, String vpcUuid, String domainTemplateName) throws Exception;
    --- End diff --
    
    Why is Exception declared in the throws instead of the list of expected checked exceptions on all of these methods?
    
    Also, ``public`` modifiers on ``public interface`` declarations are extraneous. 


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41778534
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -368,18 +492,15 @@ public boolean applyStaticNats(Network config, List<? extends StaticNat> rules)
                 sourceNatDetails.add(sourceNatDetail);
             }
             try {
    -            try {
    -                HostVO nuageVspHost = getNuageVspHost(config.getPhysicalNetworkId());
    -                ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(networkDomain.getUuid(), vpcOrSubnetUuid, isL3Network, sourceNatDetails);
    -                ApplyStaticNatVspAnswer answer = (ApplyStaticNatVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -                if (answer == null || !answer.getResult()) {
    -                    s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed");
    -                    if ((null != answer) && (null != answer.getDetails())) {
    -                        throw new ResourceUnavailableException(answer.getDetails(), Network.class, config.getId());
    -                    }
    +            HostVO nuageVspHost = getNuageVspHost(config.getPhysicalNetworkId());
    +            ApplyStaticNatVspCommand.Builder cmdBuilder = new ApplyStaticNatVspCommand.Builder().networkDomainUuid(networkDomain.getUuid())
    +                    .networkUuid(config.getUuid()).vpcOrSubnetUuid(vpcOrSubnetUuid).isL3Network(isL3Network).isVpc(vpcId != null).staticNatDetails(sourceNatDetails);
    +            ApplyStaticNatVspAnswer answer = (ApplyStaticNatVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
    +            if (answer == null || !answer.getResult()) {
    +                s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed");
    +                if ((null != answer) && (null != answer.getDetails())) {
    +                    throw new ResourceUnavailableException(answer.getDetails(), Network.class, config.getId());
                     }
    -            } catch (Exception e) {
    -                s_logger.warn("Failed to apply static Nat in Vsp " + e.getMessage());
                 }
             } catch (Exception e) {
    --- End diff --
    
    Why are all checked and unchecked exceptions being caught here?  Why not catch the subset of expected checked exceptions?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-150268787
  
    I will review the changes late today or early tomorrow.  I have a few items I need to attend to first.
    
    
    
    > On Oct 22, 2015, at 11:16 AM, Kris Sterckx <no...@github.com> wrote:
    > 
    > @remibergsma how can we continue pls ? Could you run Travis again ? Can we do anything ? Thanks
    > 
    > —
    > Reply to this email directly or view it on GitHub.
    > 



---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by remibergsma <gi...@git.apache.org>.
Github user remibergsma commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-157680581
  
    LGTM, based on a set of tests that I run on this branch (which I rebased myself first now that master moved on):
    
    ```
    nosetests --with-marvin --marvin-config=${marvinCfg} -s -a tags=advanced,required_hardware=true \
    component/test_vpc_redundant.py \
    component/test_routers_iptables_default_policy.py \
    component/test_routers_network_ops.py \
    component/test_vpc_router_nics.py \
    smoke/test_loadbalance.py \
    smoke/test_internal_lb.py \
    smoke/test_ssvm.py \
    smoke/test_network.py
    
    ```
    
    Result:
    
    ```
    Create a redundant VPC with two networks with two VMs in each network ... === TestName: test_01_create_redundant_VPC_2tiers_4VMs_4IPs_4PF_ACL | St
    atus : SUCCESS ===
    ok
    Create a redundant VPC with two networks with two VMs in each network and check default routes ... === TestName: test_02_redundant_VPC_default_rou
    tes | Status : SUCCESS ===
    ok
    Test iptables default INPUT/FORWARD policy on RouterVM ... === TestName: test_02_routervm_iptables_policies | Status : SUCCESS ===
    ok
    Test iptables default INPUT/FORWARD policies on VPC router ... === TestName: test_01_single_VPC_iptables_policies | Status : SUCCESS ===
    ok
    Test redundant router internals ... === TestName: test_01_isolate_network_FW_PF_default_routes_egress_true | Status : SUCCESS ===
    ok
    Test redundant router internals ... === TestName: test_02_isolate_network_FW_PF_default_routes_egress_false | Status : SUCCESS ===
    ok
    Test redundant router internals ... === TestName: test_01_RVR_Network_FW_PF_SSH_default_routes_egress_true | Status : SUCCESS ===
    ok
    Test redundant router internals ... === TestName: test_02_RVR_Network_FW_PF_SSH_default_routes_egress_false | Status : SUCCESS ===
    ok
    Create a VPC with two networks with one VM in each network and test nics after destroy ... === TestName: test_01_VPC_nics_after_destroy | Status :
     SUCCESS ===
    ok
    Create a VPC with two networks with one VM in each network and test default routes ... === TestName: test_02_VPC_default_routes | Status : SUCCESS
     ===
    ok
    Check the password file in the Router VM ... === TestName: test_isolate_network_password_server | Status : SUCCESS ===
    ok
    Check that the /etc/dhcphosts.txt doesn't contain duplicate IPs ... === TestName: test_router_dhcphosts | Status : SUCCESS ===
    ok
    Test to create Load balancing rule with source NAT ... === TestName: test_01_create_lb_rule_src_nat | Status : SUCCESS ===
    ok
    Test to create Load balancing rule with non source NAT ... === TestName: test_02_create_lb_rule_non_nat | Status : SUCCESS ===
    ok
    Test for assign & removing load balancing rule ... === TestName: test_assign_and_removal_lb | Status : SUCCESS ===
    ok
    Test to verify access to loadbalancer haproxy admin stats page ... === TestName: test02_internallb_haproxy_stats_on_all_interfaces | Status : SUCC
    ESS ===
    ok
    Test create, assign, remove of an Internal LB with roundrobin http traffic to 3 vm's ... === TestName: test_01_internallb_roundrobin_1VPC_3VM_HTTP
    _port80 | Status : SUCCESS ===
    ok
    Test SSVM Internals ... === TestName: test_03_ssvm_internals | Status : SUCCESS ===
    ok
    Test CPVM Internals ... === TestName: test_04_cpvm_internals | Status : SUCCESS ===
    ok
    Test stop SSVM ... === TestName: test_05_stop_ssvm | Status : SUCCESS ===
    ok
    Test stop CPVM ... === TestName: test_06_stop_cpvm | Status : SUCCESS ===
    ok
    Test reboot SSVM ... === TestName: test_07_reboot_ssvm | Status : SUCCESS ===
    ok
    Test reboot CPVM ... === TestName: test_08_reboot_cpvm | Status : SUCCESS ===
    ok
    Test destroy SSVM ... === TestName: test_09_destroy_ssvm | Status : SUCCESS ===
    ok
    Test destroy CPVM ... === TestName: test_10_destroy_cpvm | Status : SUCCESS ===
    ok
    Test Remote Access VPN in VPC ... === TestName: test_vpc_remote_access_vpn | Status : SUCCESS ===
    ok
    Test VPN in VPC ... === TestName: test_vpc_site2site_vpn | Status : SUCCESS ===
    ok
    Test for port forwarding on source NAT ... === TestName: test_01_port_fwd_on_src_nat | Status : SUCCESS ===
    ok
    Test for port forwarding on non source NAT ... === TestName: test_02_port_fwd_on_non_src_nat | Status : SUCCESS ===
    ok
    Test for reboot router ... === TestName: test_reboot_router | Status : SUCCESS ===
    ok
    Test for Router rules for network rules on acquired public IP ... === TestName: test_network_rules_acquired_public_ip_1_static_nat_rule | Status :
     SUCCESS ===
    ok
    Test for Router rules for network rules on acquired public IP ... === TestName: test_network_rules_acquired_public_ip_2_nat_rule | Status : SUCCES
    S ===
    ok
    Test for Router rules for network rules on acquired public IP ... === TestName: test_network_rules_acquired_public_ip_3_Load_Balancer_Rule | Statu
    s : SUCCESS ===
    ok
    
    ----------------------------------------------------------------------
    Ran 33 tests in 14659.441s
    
    OK
    ```
    
    
    And:
    
    ```
    nosetests --with-marvin --marvin-config=${marvinCfg} -s -a tags=advanced,required_hardware=false \
    smoke/test_routers.py \
    smoke/test_network_acl.py \
    smoke/test_privategw_acl.py \
    smoke/test_reset_vm_on_reboot.py \
    smoke/test_vm_life_cycle.py \
    smoke/test_vpc_vpn.py \
    smoke/test_service_offerings.py \
    component/test_vpc_offerings.py \
    component/test_vpc_routers.py
    ```
    
    Result:
    
    ```
    Test router internal advanced zone ... === TestName: test_02_router_internal_adv | Status : SUCCESS ===
    ok
    Test restart network ... === TestName: test_03_restart_network_cleanup | Status : SUCCESS ===
    ok
    Test router basic setup ... === TestName: test_05_router_basic | Status : SUCCESS ===
    ok
    Test router advanced setup ... === TestName: test_06_router_advanced | Status : SUCCESS ===
    ok
    Test stop router ... === TestName: test_07_stop_router | Status : SUCCESS ===
    ok
    Test start router ... === TestName: test_08_start_router | Status : SUCCESS ===
    ok
    Test reboot router ... === TestName: test_09_reboot_router | Status : SUCCESS ===
    ok
    test_privategw_acl (integration.smoke.test_privategw_acl.TestPrivateGwACL) ... === TestName: test_privategw_acl | Status : SUCCESS ===
    ok
    Test reset virtual machine on reboot ... === TestName: test_01_reset_vm_on_reboot | Status : SUCCESS ===
    ok
    Test advanced zone virtual router ... === TestName: test_advZoneVirtualRouter | Status : SUCCESS ===
    ok
    Test Deploy Virtual Machine ... === TestName: test_deploy_vm | Status : SUCCESS ===
    ok
    Test Multiple Deploy Virtual Machine ... === TestName: test_deploy_vm_multiple | Status : SUCCESS ===
    ok
    Test Stop Virtual Machine ... === TestName: test_01_stop_vm | Status : SUCCESS ===
    ok
    Test Start Virtual Machine ... === TestName: test_02_start_vm | Status : SUCCESS ===
    ok
    Test Reboot Virtual Machine ... === TestName: test_03_reboot_vm | Status : SUCCESS ===
    ok
    Test destroy Virtual Machine ... === TestName: test_06_destroy_vm | Status : SUCCESS ===
    ok
    Test recover Virtual Machine ... === TestName: test_07_restore_vm | Status : SUCCESS ===
    ok
    Test migrate VM ... === TestName: test_08_migrate_vm | Status : SUCCESS ===
    ok
    Test destroy(expunge) Virtual Machine ... === TestName: test_09_expunge_vm | Status : SUCCESS ===
    ok
    Test to create service offering ... === TestName: test_01_create_service_offering | Status : SUCCESS ===
    ok
    Test to update existing service offering ... === TestName: test_02_edit_service_offering | Status : SUCCESS ===
    ok
    Test to delete service offering ... === TestName: test_03_delete_service_offering | Status : SUCCESS ===
    ok
    Test for delete account ... === TestName: test_delete_account | Status : SUCCESS ===
    ok
    Test for Associate/Disassociate public IP address for admin account ... === TestName: test_public_ip_admin_account | Status : SUCCESS ===
    ok
    Test for Associate/Disassociate public IP address for user account ... === TestName: test_public_ip_user_account | Status : SUCCESS ===
    ok
    Test for release public IP address ... === TestName: test_releaseIP | Status : SUCCESS ===
    ok
    Test create VPC offering ... === TestName: test_01_create_vpc_offering | Status : SUCCESS ===
    ok
    Test VPC offering without load balancing service ... === TestName: test_03_vpc_off_without_lb | Status : SUCCESS ===
    ok
    Test VPC offering without static NAT service ... === TestName: test_04_vpc_off_without_static_nat | Status : SUCCESS ===
    ok
    Test VPC offering without port forwarding service ... === TestName: test_05_vpc_off_without_pf | Status : SUCCESS ===
    ok
    Test VPC offering with invalid services ... === TestName: test_06_vpc_off_invalid_services | Status : SUCCESS ===
    ok
    Test update VPC offering ... === TestName: test_07_update_vpc_off | Status : SUCCESS ===
    ok
    Test list VPC offering ... === TestName: test_08_list_vpc_off | Status : SUCCESS ===
    ok
    test_09_create_redundant_vpc_offering (integration.component.test_vpc_offerings.TestVPCOffering) ... === TestName: test_09_create_redundant_vpc_of
    fering | Status : SUCCESS ===
    ok
    Test start/stop of router after addition of one guest network ... === TestName: test_01_start_stop_router_after_addition_of_one_guest_network | St
    atus : SUCCESS ===
    ok
    Test reboot of router after addition of one guest network ... === TestName: test_02_reboot_router_after_addition_of_one_guest_network | Status : S
    UCCESS ===
    ok
    Test to change service offering of router after addition of one guest network ... === TestName: test_04_chg_srv_off_router_after_addition_of_one_g
    uest_network | Status : SUCCESS ===
    ok
    Test destroy of router after addition of one guest network ... === TestName: test_05_destroy_router_after_addition_of_one_guest_network | Status :
     SUCCESS ===
    ok
    Test to stop and start router after creation of VPC ... === TestName: test_01_stop_start_router_after_creating_vpc | Status : SUCCESS ===
    ok
    Test to reboot the router after creating a VPC ... === TestName: test_02_reboot_router_after_creating_vpc | Status : SUCCESS ===
    ok
    Tests to change service offering of the Router after ... === TestName: test_04_change_service_offerring_vpc | Status : SUCCESS ===
    ok
    Test to destroy the router after creating a VPC ... === TestName: test_05_destroy_router_after_creating_vpc | Status : SUCCESS ===
    ok
    
    ----------------------------------------------------------------------
    Ran 42 tests in 7916.599s
    
    OK
    ```
    We're all set now!


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41972355
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/VspResourceAnswer.java ---
    @@ -39,4 +39,22 @@ public VspResourceAnswer(VspResourceCommand cmd, Exception e) {
         public String getResourceInfo() {
             return this._resourceInfo;
         }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        VspResourceAnswer that = (VspResourceAnswer) o;
    +
    +        if (_resourceInfo != null ? !_resourceInfo.equals(that._resourceInfo) : that._resourceInfo != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return _resourceInfo != null ? _resourceInfo.hashCode() : 0;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code> of which <code>Answer</code> is a subclass


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43043433
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -114,7 +115,9 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
             PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
             DataCenter dc = _dcDao.findById(plan.getDataCenterId());
             if (!canHandle(offering, dc.getNetworkType(), physnet)) {
    -            s_logger.debug("Refusing to design this network");
    +            if (s_logger.isDebugEnabled()) {
    +                s_logger.debug("Refusing to design network using network offering " +  offering.getId() + (physnet != null ? " on physical network " + physnet.getId() : ""));
    --- End diff --
    
    Should this message be logged as ``WARN``?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41989892
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -437,31 +463,79 @@ private Answer executeRequest(SyncVspCommand cmd) {
                 _nuageVspSyncClient.syncWithNuageVsp(cmd.getNuageVspEntity());
                 return new SyncVspAnswer(cmd, true, "Synced " + cmd.getNuageVspEntity() + " in VSP");
             } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
                 return new SyncVspAnswer(cmd, e);
             }
         }
     
    +    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
    +                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
    +                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    +            } else if (cmd.getSyncType() == SyncType.REGISTER) {
    +                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
    +                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
    +            } else {
    +                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
    +                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
    +            }
    +        } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
    +            return new SyncNuageVspCmsIdAnswer(false, null, cmd.getSyncType());
    +        }
    +    }
    +
    +    private Answer executeRequest(SyncDomainCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomainUuid(), cmd.getDomainName(), cmd.getDomainPath(), cmd.isToAdd(), cmd.isToRemove());
    +            return new SyncDomainAnswer(success);
    +        } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
    +            return new SyncDomainAnswer(false);
    +        }
    +    }
    +
    +    private Answer executeRequest(GetClientDefaultsCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            Map<String, Object> clientDefaults = _nuageVspManagerClient.getClientDefaults();
    +            return new GetClientDefaultsAnswer(cmd, clientDefaults);
    +        } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
    --- End diff --
    
    Done.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41988458
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -285,60 +525,345 @@ 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 (!Strings.isNullOrEmpty(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);
    +                    return false;
    +                }
    +            }
    +        }
    +        return true;
    +    }
     
    -        private String nuageVspEntity;
    +    private String findNuageVspCmsIdForDevice(long deviceId, ConfigurationVO cmsIdConfig) {
    +        String configValue = cmsIdConfig.getValue();
    +        if (!Strings.isNullOrEmpty(configValue)) {
    +            String[] configuredNuageVspDevices = configValue.split(";");
    +            for (String configuredNuageVspDevice : configuredNuageVspDevices) {
    +                if (configuredNuageVspDevice.startsWith(deviceId + ":")) {
    +                    String[] split = configuredNuageVspDevice.split(":");
    +                    if (split.length != 2 || Strings.isNullOrEmpty(split[1])) {
    --- End diff --
    
    Done.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39904843
  
    --- 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());
    --- End diff --
    
    Log the exception rather than the message to provide the stack trace for debugging.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41775527
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyStaticNatVspAnswer.java ---
    @@ -31,4 +31,13 @@ public ApplyStaticNatVspAnswer(ApplyStaticNatVspCommand cmd, Exception e) {
             super(cmd, e);
         }
     
    +    @Override
    +    public boolean equals(Object obj) {
    +        return super.equals(obj);
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return super.hashCode();
    +    }
    --- End diff --
    
    Why does this class exist?  It adds no state or behavior to the ``Answer`` base class.  Why not simply use ``Answer`` in this circumstance?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39901691
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -129,66 +131,97 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
     
         @Override
         public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    -
    -        assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    -
    -        long dcId = dest.getDataCenter().getId();
    -        //Get physical network id
    -        Long physicalNetworkId = network.getPhysicalNetworkId();
    -        //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    -        if (physicalNetworkId == null) {
    -            physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    -        }
    -        NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    -                network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    -        if (network.getGateway() != null) {
    -            implemented.setGateway(network.getGateway());
    -        }
    -        if (network.getCidr() != null) {
    -            implemented.setCidr(network.getCidr());
    -        }
    -        Collection<String> ipAddressRange = new ArrayList<String>();
    -        String virtualRouterIp = getVirtualRouterIP(network, ipAddressRange);
    -        String networkUuid = implemented.getUuid();
    -        String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    -        String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    -        implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    -        implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    -        //Check if the network is associated to a VPC
    -        Long vpcId = network.getVpcId();
    -        boolean isVpc = (vpcId != null);
    -        //Check owner of the Network
    -        Domain networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    -        if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            String errorMessage = "CS project support is not yet implemented in NuageVsp";
    -            s_logger.debug(errorMessage);
    -            throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
    -        }
    -        boolean isL3Network = isL3Network(offering.getId());
    -        String vpcName = null;
    -        String vpcUuid = null;
    -        if (isVpc) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcName = vpcObj.getName();
    -            vpcUuid = vpcObj.getUuid();
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(network.getId(), 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
             }
     
    -        HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
    -        ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(networksDomain.getName(), networksDomain.getPath(), networksDomain.getUuid(),
    -                networksAccount.getAccountName(), networksAccount.getUuid(), network.getName(), network.getCidr(), network.getGateway(), network.getUuid(), isL3Network, vpcName,
    -                vpcUuid, offering.getEgressDefaultPolicy(), ipAddressRange);
    -        ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +        NetworkVO implemented = null;
    +        try {
    +            assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +
    +            long dcId = dest.getDataCenter().getId();
    +            //Get physical network id
    +            Long physicalNetworkId = network.getPhysicalNetworkId();
    +            //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    +            if (physicalNetworkId == null) {
    +                physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    +            }
    +            implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    +                    network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    +            if (network.getGateway() != null) {
    +                implemented.setGateway(network.getGateway());
    +            }
    +            if (network.getCidr() != null) {
    +                implemented.setCidr(network.getCidr());
    +            }
    +            Collection<String[]> ipAddressRanges = new ArrayList<String[]>();
    +            String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
    +            String networkUuid = implemented.getUuid();
    +            String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    +            String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    +            implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    +            implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    +            //Check if the network is associated to a VPC
    +            Long vpcId = network.getVpcId();
    +            boolean isVpc = (vpcId != null);
    +            //Check owner of the Network
    +            Domain networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    +            if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                String errorMessage = "CS project support is not yet implemented in NuageVsp";
    +                s_logger.debug(errorMessage);
    +                throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
    +            }
    +            String vpcName = null;
    +            String vpcUuid = null;
    +            String preConfiguredDomainTemplateName = null;
    +            boolean isL3Network = false, isSharedNetwork = false;
    +            if (isVpc) {
    +                Vpc vpcObj = _vpcDao.findById(vpcId);
    +                vpcName = vpcObj.getName();
    +                vpcUuid = vpcObj.getUuid();
    +                preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key());
    +            } else {
    +                if (offering.getGuestType() == GuestType.Shared) {
    +                    isL3Network = true;
    +                    isSharedNetwork = true;
    +                    preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspSharedNetworkDomainTemplateName.key());
    +
    +                    ipAddressRanges = new ArrayList<String[]>();
    +                    List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
    +                    for (VlanVO vlan : vlans) {
    +                        boolean isIpv4 = StringUtils.isNotBlank(vlan.getIpRange());
    +                        String[] range = isIpv4 ? vlan.getIpRange().split("-") : vlan.getIp6Range().split("-");
    +                        ipAddressRanges.add(range);
    +                    }
    +                } else if (isL3Network(network)) {
    +                    isL3Network = true;
    +                    preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspIsolatedNetworkDomainTemplateName.key());
    +                }
    +            }
    +
    +            HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
    +            List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +            List<String> gatewaySystemIds = _nuageVspManager.getGatewaySystemIds();
    +            ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(networksDomain.getName(), networksDomain.getPath(), networksDomain.getUuid(), networksAccount.getAccountName(),
    +                    networksAccount.getUuid(), network.getName(), network.getCidr(), network.getGateway(), network.getNetworkACLId(), dnsServers, gatewaySystemIds, network.getUuid(),
    +                    isL3Network, isVpc, isSharedNetwork, vpcName, vpcUuid, offering.getEgressDefaultPolicy(), ipAddressRanges, preConfiguredDomainTemplateName);
    +            ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
     
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ImplementNetworkNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +            if (answer == null || !answer.getResult()) {
    +                s_logger.error("ImplementNetworkNuageVspCommand failed");
    +                if ((null != answer) && (null != answer.getDetails())) {
    +                    s_logger.error(answer.getDetails());
    +                }
    +                return null;
                 }
    -            return null;
    +            s_logger.info("Implemented OK, network " + networkUuid + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri().toString());
    --- End diff --
    
    The call to ``implemented.getBroadcastUri().toString()`` in extraneous.  Append ``implemented.getBroadcastUri()`` and the compiler will automatically insert the ``toString()`` call.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41979553
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/UpdateNuageVspDeviceCommand.java ---
    @@ -0,0 +1,60 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api;
    +
    +import java.util.Collections;
    +import java.util.Map;
    +
    +public class UpdateNuageVspDeviceCommand extends Command {
    +
    +    private final Map<String, String> _parametersToBeUpdated;
    +
    +    public UpdateNuageVspDeviceCommand(Map<String, String> parametersToBeUpdated) {
    +        super();
    +        this._parametersToBeUpdated = parametersToBeUpdated;
    --- End diff --
    
    Used <code>ImmutableMap.copyOf()</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031444
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java ---
    @@ -0,0 +1,79 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Answer;
    +
    +import java.util.Map;
    +
    +public class GetClientDefaultsAnswer extends Answer {
    +
    +    private String _currentApiVersion;
    +    private Integer _apiRetryCount;
    +    private Long _apiRetryInterval;
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Map<String, Object> defaults) {
    +        super(cmd);
    +        this._currentApiVersion = (String) defaults.get("CURRENT_API_VERSION");
    +        this._apiRetryCount = (Integer) defaults.get("DEFAULT_API_RETRY_COUNT");
    +        this._apiRetryInterval = (Long) defaults.get("DEFAULT_API_RETRY_INTERVAL");
    +    }
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Exception e) {
    +        super(cmd, e);
    +    }
    +
    +    public String getCurrentApiVersion() {
    +        return _currentApiVersion;
    +    }
    +
    +    public Integer getApiRetryCount() {
    +        return _apiRetryCount;
    +    }
    +
    +    public Long getApiRetryInterval() {
    +        return _apiRetryInterval;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This ``equals`` implementation should include attributes from the ``Answer`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39896365
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncNuageVspCmsIdAnswer.java ---
    @@ -0,0 +1,49 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Answer;
    +
    +public class SyncNuageVspCmsIdAnswer extends Answer {
    +
    +    boolean _success;
    +    String _nuageVspCmsId;
    +    SyncNuageVspCmsIdCommand.SyncType _syncType;
    --- End diff --
    
    Why aren't these attributes declared private? It doesn't appear to modified outside of the constructor. Why aren't they declared final as well?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43050493
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,50 +241,185 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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) {
    --- End diff --
    
    Simply this block by checking if the host is ``null`` throwing an exception before proceeding further in the method.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43050603
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,50 +241,185 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @Override
    -                    public NuageVspDeviceVO doInTransaction(TransactionStatus status) {
    -                        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);
    -
    -                        return 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 (ConfigurationException e) {
    -            throw new CloudRuntimeException(e.getMessage());
    +            s_logger.error("Failed to configure Nuage VSD resource", e);
    +            throw new CloudRuntimeException("Failed to configure Nuage VSD resource", e);
    +        } catch (ExecutionException ee) {
    +            s_logger.error("Failed to add Nuage VSP device", ee);
    +            throw new CloudRuntimeException("Failed to add Nuage VSP device", ee);
    --- End diff --
    
    Please add identifying information about the Nuage device to the error messages.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41806263
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -441,6 +456,44 @@ private Answer executeRequest(SyncVspCommand cmd) {
             }
         }
     
    +    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
    +                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
    +                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    +            } else if (cmd.getSyncType() == SyncType.REGISTER) {
    +                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
    +                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
    +            } else {
    +                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
    +                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
    +            }
    +        } catch (Exception e) {
    --- End diff --
    
    Why are all unchecked and checked exceptions being caught?  It seems like we should only be catching the expected checked exceptions, and allow unchecked exceptions simply bubble out.


---
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.
---

Re: [GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by Mike Tutkowski <mi...@solidfire.com>.
I agree, John, that visual code inspection is not sufficient to "prove" the
code behaves as expected (too many variables to take into consideration
that just examining the code can easily miss problems).

I believe the idea, though, was just to protect the state of the DB since
the plug-ins don't run in sandboxes. If a customer wants to use CloudStack
with SolidFire and should happen to encounter an issue or question, I would
expect the customer would contact SolidFire about the issue/question. I
think for some plug-ins that this is the case and for others it is not. I
think for the ones where this is not the case (i.e. issues/questions come
to the CS community and not to a particular vendor), we should try to
enforce more strict community requirements for testing.

On Wed, Nov 4, 2015 at 11:35 AM, jburwell <gi...@git.apache.org> wrote:

> Github user jburwell commented on the pull request:
>
>     https://github.com/apache/cloudstack/pull/801#issuecomment-153822915
>
>     I agree with @runseb that we need to move this discussion to dev@,
> and re-assess accepting the maintenance responsibly for code that cannot be
> tested and verified by the community.  This plugin has already been
> accepted into 4.5, and as such, would be "grandfathered" into any decision
> we would make.  Therefore, we should carry our current precedent forward
> and not prevent acceptance of this PR for this reason.  We are at a point
> in the 4.6 release cycle that only blockers should be accepted.  Otherwise,
> we will never ship 4.6.
>
>     @KrisSterckx I realize my comments may come across as unappreciative
> which is not my intention.  I greatly appreciate the work @nlivens and you
> have done to contribute this capability to the community.  This plugin
> highlights a larger issue which is that, as a community, we are delivering
> releases containing code that cannot be verified.  By contributing this
> plugin to our community, we become responsible for its support and
> maintenance.  In 6-12 months, how do answer answer a user who asks does
> this plugin work in the latest release if you are unavailable?
>
>     @runseb while there is a fairness issue for the contributor, I think
> it is incredibly unfair to our users that we ship code without on-going
> validation.  When a user sees the availability of PluginX supporting
> Device1 in a release, they assume that we have verified the proper
> operation of PluginX since we shipped it in that release.  In fact, we
> haven't, and they may be attempting to use something that is completely
> broken.
>
>     @mlsorensen yes, plugins provide a mechanism for vendors to extend
> CloudStack.  However, there is no requirement for those plugins to be part
> of the community, OSS codebase.  Therefore, we should not conflate the
> ability of third-parties to extend CloudStack using plugins with the code
> that is accepted as part of the community's repositories.  All code in our
> repositories, regardless of being in the core or a plugin, should be held
> to the same standards.  When a user has a problem, they aren't any less
> frustrated with the project because their problem happens to be in a plugin.
>
>     @mike-tutkowski I don't believe that code inspection by itself is
> adequate to determine the quality of code integrating an external device.
> For example, I reviewed the code for this plugin, and while I feel
> confident that it will behave well within the management server, I have
> absolutely no idea if the various network functions are being properly
> automated using the Nuage client APIs.  The only way for those aspects of
> the plugin's operation to be verified would be to run in a test environment
> with a Nuage device and realize a set of network topologies.
>
>
> ---
> 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.
> ---
>



-- 
*Mike Tutkowski*
*Senior CloudStack Developer, SolidFire Inc.*
e: mike.tutkowski@solidfire.com
o: 303.746.7302
Advancing the way the world uses the cloud
<http://solidfire.com/solution/overview/?video=play>*™*

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-153822915
  
    I agree with @runseb that we need to move this discussion to dev@, and re-assess accepting the maintenance responsibly for code that cannot be tested and verified by the community.  This plugin has already been accepted into 4.5, and as such, would be "grandfathered" into any decision we would make.  Therefore, we should carry our current precedent forward and not prevent acceptance of this PR for this reason.  We are at a point in the 4.6 release cycle that only blockers should be accepted.  Otherwise, we will never ship 4.6.
    
    @KrisSterckx I realize my comments may come across as unappreciative which is not my intention.  I greatly appreciate the work @nlivens and you have done to contribute this capability to the community.  This plugin highlights a larger issue which is that, as a community, we are delivering releases containing code that cannot be verified.  By contributing this plugin to our community, we become responsible for its support and maintenance.  In 6-12 months, how do answer answer a user who asks does this plugin work in the latest release if you are unavailable?
    
    @runseb while there is a fairness issue for the contributor, I think it is incredibly unfair to our users that we ship code without on-going validation.  When a user sees the availability of PluginX supporting Device1 in a release, they assume that we have verified the proper operation of PluginX since we shipped it in that release.  In fact, we haven't, and they may be attempting to use something that is completely broken.
    
    @mlsorensen yes, plugins provide a mechanism for vendors to extend CloudStack.  However, there is no requirement for those plugins to be part of the community, OSS codebase.  Therefore, we should not conflate the ability of third-parties to extend CloudStack using plugins with the code that is accepted as part of the community's repositories.  All code in our repositories, regardless of being in the core or a plugin, should be held to the same standards.  When a user has a problem, they aren't any less frustrated with the project because their problem happens to be in a plugin.  
    
    @mike-tutkowski I don't believe that code inspection by itself is adequate to determine the quality of code integrating an external device.  For example, I reviewed the code for this plugin, and while I feel confident that it will behave well within the management server, I have absolutely no idea if the various network functions are being properly automated using the Nuage client APIs.  The only way for those aspects of the plugin's operation to be verified would be to run in a test environment with a Nuage device and realize a set of network topologies.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39967023
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspManagerClient.java ---
    @@ -0,0 +1,41 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package net.nuage.vsp.acs.client;
    +
    +import org.apache.commons.lang3.tuple.Pair;
    +
    +import java.util.Map;
    +
    +public interface NuageVspManagerClient {
    +
    +    public Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws Exception;
    +
    +    public String registerNuageVspCmsId() throws Exception;
    +
    +    public boolean unregisterNuageVspCmsId(String nuageVspCmsId) throws Exception;
    +
    +    public boolean isSupportedApiVersion(String version);
    +
    +    public Map<String, Object> getClientDefaults() throws Exception;
    +
    +    public boolean syncDomainWithNuageVsp(String domainUuid, String domainName, String domainPath, boolean add, boolean remove) throws Exception;
    +
    +    public <C extends NuageVspApiClient> void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
    --- End diff --
    
    The private client is using custom exceptions which are translated to global exceptions for use inside the CS plugin


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43095562
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -129,66 +132,93 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
     
         @Override
         public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(network.getId(), 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
    +        }
    +
    +        NetworkVO implemented = null;
    +        try {
    +            assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    --- End diff --
    
    Done.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-139987547
  
    @bhaisaab, I've added some more unit tests on top of the existing ones


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41806067
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -360,32 +375,25 @@ private Answer executeRequest(ImplementNetworkVspCommand cmd) {
         private Answer executeRequest(ReserveVmInterfaceVspCommand cmd) {
             try {
                 isNuageVspGuruLoaded();
    -            List<Map<String, String>> vmInterfaceInfo = _nuageVspGuruClient.reserve(cmd.getNicUuid(), cmd.getNicMacAddress(), cmd.getNetworkUuid(), cmd.isL3Network(),
    -                    cmd.getVpcUuid(), cmd.getNetworkDomainUuid(), cmd.getNetworksAccountUuid(), cmd.isDomainRouter(), cmd._getDomainRouterIp(), cmd._getVmInstanceName(),
    -                    cmd._getVmUuid());
    -            return new ReserveVmInterfaceVspAnswer(cmd, vmInterfaceInfo, "Created NIC in VSP that maps to nicUuid" + cmd.getNicUuid());
    +            _nuageVspGuruClient.reserve(cmd.getNicUuid(), cmd.getNicMacAddress(), cmd.getNetworkUuid(), cmd.isL3Network(),
    +                    cmd.isSharedNetwork(), cmd.getVpcUuid(), cmd.getNetworkDomainUuid(), cmd.getNetworksAccountUuid(), cmd.isDomainRouter(), cmd.getDomainRouterIp(),
    +                    cmd.getVmInstanceName(), cmd.getVmUuid(), cmd.useStaticIp(), cmd.getStaticIp(), cmd.getStaticNatIpUuid(), cmd.getStaticNatIpAddress(), cmd.isStaticNatIpAllocated(),
    +                    cmd.isOneToOneNat(), cmd.getStaticNatVlanUuid(), cmd.getStaticNatVlanGateway(), cmd.getStaticNatVlanNetmask());
    +            return new ReserveVmInterfaceVspAnswer(cmd, "Created NIC in VSP that maps to nicUuid" + cmd.getNicUuid());
    --- End diff --
    
    Please add identifying for the Nuage VSP device to assist with operational debugging.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by remibergsma <gi...@git.apache.org>.
Github user remibergsma commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-147175350
  
    Thanks @KrisSterckx but please remove the merge commit (using `rebase -i`)


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43091957
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/PingNuageVspCommand.java ---
    @@ -17,18 +17,37 @@
     // under the License.
     //
     
    -package com.cloud.agent.api.element;
    +package com.cloud.agent.api;
     
    -import com.cloud.agent.api.Answer;
    +import com.cloud.host.Host;
     
    -public class ShutDownVpcVspAnswer extends Answer {
    +public class PingNuageVspCommand extends PingCommand {
     
    -    public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, boolean success, String details) {
    -        super(cmd, success, details);
    +    private final boolean shouldAudit;
    +
    +    public PingNuageVspCommand(Host.Type type, long id, boolean shouldAudit) {
    +        super(type, id);
    +        this.shouldAudit = shouldAudit;
         }
     
    -    public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, Exception e) {
    -        super(cmd, e);
    +    public boolean shouldAudit() {
    +        return shouldAudit;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        PingNuageVspCommand that = (PingNuageVspCommand) o;
    +
    +        if (shouldAudit != that.shouldAudit) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Added attributes from the <code>PingCommand</code> super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43048038
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,50 +241,185 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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());
    --- End diff --
    
    This behavior feels like a leaky abstraction.   Consider adding a method to the command to encapsulate this behavior and ensure consistency across all usages.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41984944
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +442,28 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
     
             if (allIPsInCidr.size() > 3) {
    +            //get the second IP and see if it the networks GatewayIP
                 Iterator<Long> ipIterator = allIPsInCidr.iterator();
                 long vip = ipIterator.next();
                 if (NetUtils.ip2Long(network.getGateway()) == vip) {
    -                s_logger.debug("Gateway of the Network(" + network.getUuid() + ") has the first IP " + NetUtils.long2Ip(vip));
    +                if (s_logger.isDebugEnabled()) {
    +                    s_logger.debug("Gateway of the Network(" + network.getName() + ") has the first IP " + NetUtils.long2Ip(vip));
    +                }
                     vip = ipIterator.next();
                     virtualRouterIp = NetUtils.long2Ip(vip);
    -                s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getUuid() + ")");
    +                if (s_logger.isDebugEnabled()) {
    +                    s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getName() + ")");
    +                }
                 } else {
                     virtualRouterIp = NetUtils.long2Ip(vip);
    -                s_logger.debug("1nd IP is not used as the gateway IP. So, reserving" + virtualRouterIp + " for the Virtual Router IP for " + "Network(" + network.getUuid() + ")");
    +                if (s_logger.isDebugEnabled()) {
    +                    s_logger.debug("1nd IP is not used as the gateway IP. So, reserving" + virtualRouterIp + " for the Virtual Router IP for " + "Network(" + network.getName() + ")");
    --- End diff --
    
    Changed the latter message to contain the previous one.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093020
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyStaticNatVspCommand.java ---
    @@ -51,13 +61,91 @@ public boolean isL3Network() {
             return _isL3Network;
         }
     
    +    public boolean isVpc() {
    +        return _isVpc;
    +    }
    +
         public List<Map<String, Object>> getStaticNatDetails() {
             return _staticNatDetails;
         }
     
    +    public static class Builder implements CmdBuilder<ApplyStaticNatVspCommand> {
    +        private String _networkDomainUuid;
    +        private String _networkUuid;
    +        private String _vpcOrSubnetUuid;
    +        private boolean _isL3Network;
    +        private boolean _isVpc;
    +        private List<Map<String, Object>> _staticNatDetails;
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
    +            this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isVpc(boolean isVpc) {
    +            this._isVpc = isVpc;
    +            return this;
    +        }
    +
    +        public Builder staticNatDetails(List<Map<String, Object>> staticNatDetails) {
    +            this._staticNatDetails = staticNatDetails;
    +            return this;
    +        }
    +
    +        @Override
    +        public ApplyStaticNatVspCommand build() {
    +            return new ApplyStaticNatVspCommand(_networkDomainUuid, _networkUuid, _vpcOrSubnetUuid, _isL3Network, _isVpc, _staticNatDetails);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ApplyStaticNatVspCommand that = (ApplyStaticNatVspCommand) o;
    +
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isVpc != that._isVpc) return false;
    +        if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
    +            return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_staticNatDetails != null ? !_staticNatDetails.equals(that._staticNatDetails) : that._staticNatDetails != null)
    +            return false;
    +        if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41778327
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -205,9 +254,79 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
                 return false;
             }
     
    +        final boolean egressDefaultPolicy = offering.getEgressDefaultPolicy();
    +        Domain networkDomain = _domainDao.findById(network.getDomainId());
    +        boolean isFirewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.Firewall);
    +        List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +
    +        boolean isL2Network = false, isL3Network = false, isShared = false;
    +        String subnetUuid = network.getUuid();
    +        if (offering.getGuestType() == Network.GuestType.Shared) {
    +            isShared = true;
    +            subnetUuid = networkDomain.getUuid();
    +        } else if (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.StaticNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
    +            isL3Network = true;
    +        } else {
    +            isL2Network = true;
    +        }
    +
    +        String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
    +        List<FirewallRuleVO> firewallIngressRulesToApply = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Ingress);
    +        List<FirewallRuleVO> firewallEgressRulesToApply = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Egress);
    +
    +        List<Map<String, Object>> ingressFirewallRules = Lists.transform(firewallIngressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<Map<String, Object>> egressFirewallRules = Lists.transform(firewallEgressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
    +        List<String> acsFipUuid = new ArrayList<String>();
    +        for (IPAddressVO ip : ips) {
    +            acsFipUuid.add(ip.getUuid());
    +        }
    +
    +        try {
    +            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    +            ImplementVspCommand.Builder cmdBuilder = new ImplementVspCommand.Builder().networkId(network.getId()).networkDomainUuid(networkDomain.getUuid())
    +                    .networkUuid(network.getUuid()).networkName(network.getName()).vpcOrSubnetUuid(subnetUuid).isL2Network(isL2Network).isL3Network(isL3Network)
    +                    .isVpc(false).isShared(isShared).domainTemplateName(preConfiguredDomainTemplateName).isFirewallServiceSupported(isFirewallServiceSupported)
    +                    .dnsServers(dnsServers).ingressFirewallRules(ingressFirewallRules).egressFirewallRules(egressFirewallRules).acsFipUuid(acsFipUuid)
    +                    .egressDefaultPolicy(egressDefaultPolicy);
    +            ImplementVspAnswer answer = (ImplementVspAnswer) _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
    +            if (answer == null || !answer.getResult()) {
    +                s_logger.error("ImplementVspCommand for network " + network.getUuid() + " failed");
    +                if ((null != answer) && (null != answer.getDetails())) {
    +                    throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
    +                }
    +            }
    +        } catch (Exception e) {
    +            s_logger.warn("Failed to implement network in Vsp", e);
    --- End diff --
    
    Why is this message being logged to ``WARN`` instead of ``ERROR``.  The behavior indicates that this condition halts operation.  Also, please add context information about the VSP to help admins determine instance encountered a problem.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43053099
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -112,8 +111,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
                 throw new ConfigurationException("Unable to find zone");
             }
     
    -        String hostname = (String)params.get("hostname");
    -        if (hostname == null) {
    +        _hostName = (String)params.get("hostname");
    +        if (_hostName == null) {
    --- End diff --
    
    Should this value be checked with ``Strings.isNullorEmpty()``?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807853
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspManagerClient.java ---
    @@ -0,0 +1,41 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package net.nuage.vsp.acs.client;
    +
    +import org.apache.commons.lang3.tuple.Pair;
    +
    +import java.util.Map;
    +
    +public interface NuageVspManagerClient {
    +
    +    Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws Exception;
    +
    +    String registerNuageVspCmsId() throws Exception;
    +
    +    boolean unregisterNuageVspCmsId(String nuageVspCmsId) throws Exception;
    +
    +    boolean isSupportedApiVersion(String version);
    +
    +    Map<String, Object> getClientDefaults() throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39901880
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -201,51 +234,82 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil
         @Override
         public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
                 throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    -        nic.setBroadcastUri(network.getBroadcastUri());
    -        nic.setIsolationUri(network.getBroadcastUri());
    -
    -        s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    -        DataCenter dc = _dcDao.findById(network.getDataCenterId());
    -        Account networksAccount = _accountDao.findById(network.getAccountId());
    -        DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        long networkOwnedBy = network.getAccountId();
    -        AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    -        if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
             }
     
    -        //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    -        //that we create in VSP
    -        NicVO nicFrmDB = _nicDao.findById(nic.getId());
    -        long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
    -        boolean isL3Network = isL3Network(networkOfferingId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    -        }
    -        HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -        ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(nicFrmDB.getUuid(), nic.getMacAddress(), network.getUuid(), isL3Network, vpcUuid,
    -                networksDomain.getUuid(), networksAccount.getUuid(), vm.getType().equals(VirtualMachine.Type.DomainRouter), network.getBroadcastUri().getPath().substring(1),
    -                vm.getInstanceName(), vm.getUuid(), networksDomain.getUuid(), networksAccount.getUuid());
    -        ReserveVmInterfaceVspAnswer answer = (ReserveVmInterfaceVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ReserveVmInterfaceNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +        try {
    +            nic.setBroadcastUri(network.getBroadcastUri());
    +            nic.setIsolationUri(network.getBroadcastUri());
    +
    +            s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    +            DataCenter dc = _dcDao.findById(network.getDataCenterId());
    +            Account networksAccount = _accountDao.findById(network.getAccountId());
    +            DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            long networkOwnedBy = network.getAccountId();
    +            AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    +            if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +            }
    +
    --- End diff --
    
    Remove the unnecessary whitespace.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41990167
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspGuruClient.java ---
    @@ -21,24 +21,22 @@
     
     import java.util.Collection;
     import java.util.List;
    -import java.util.Map;
     
     public interface NuageVspGuruClient {
     
    -    public void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
    -            String networkCidr, String networkGateway, String networkUuid, boolean isL3Network, String vpcName, String vpcUuid, boolean defaultEgressPolicy,
    -            Collection<String> ipAddressRange) throws Exception;
    +    void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
    +                          String networkCidr, String networkGateway, Long networkAclId, List<String> dnsServers, List<String> gatewaySystemIds, boolean isL3Network, boolean isVpc, boolean isSharedNetwork,
    +                          String networkUuid, String vpcName, String vpcUuid, boolean defaultEgressPolicy, Collection<String[]> ipAddressRange, String domainTemplateName) throws Exception;
     
    -    public List<Map<String, String>> reserve(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, String vpcUuid, String networkDomainUuid,
    -            String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid) throws Exception;
    +    void reserve(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String networkDomainUuid,
    +                                             String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid, boolean useStaticIp, String staticIp, String staticNatIpUuid,
    +                                             String staticNatIpAddress, boolean isStaticNatIpAllocated, boolean isOneToOneNat, String staticNatVlanUuid, String staticNatVlanGateway, String staticNatVlanNetmask) throws Exception;
    --- End diff --
    
    This is how the methods are declared in our client. They need to have the same signature as defined in our client.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41972015
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainAnswer.java ---
    @@ -0,0 +1,54 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Answer;
    +
    +public class SyncDomainAnswer extends Answer {
    +
    +    private final boolean _success;
    +
    +    public SyncDomainAnswer(boolean success) {
    +        super();
    +        this._success = success;
    +    }
    +
    +    public boolean getSuccess() {
    +        return _success;
    +    }
    +
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncDomainAnswer that = (SyncDomainAnswer) o;
    +
    +        if (_success != that._success) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return (_success ? 1 : 0);
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code> of which <code>Answer</code> is a subclass


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39903111
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +441,22 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
    --- End diff --
    
    Pass ``Collections.emptySet()`` rather than allocating a new empty ``HashSet`` on each call.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41778939
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -129,66 +134,94 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
     
         @Override
         public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(network.getId(), 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
    +        }
     
    -        assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +        NetworkVO implemented = null;
    +        try {
    +            assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +
    +            long dcId = dest.getDataCenter().getId();
    +            //Get physical network id
    +            Long physicalNetworkId = network.getPhysicalNetworkId();
    +            //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    +            if (physicalNetworkId == null) {
    +                physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    +            }
    +            implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    +                    network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    +            if (network.getGateway() != null) {
    +                implemented.setGateway(network.getGateway());
    +            }
    +            if (network.getCidr() != null) {
    +                implemented.setCidr(network.getCidr());
    +            }
    +            List<String[]> ipAddressRanges = new ArrayList<String[]>();
    +            String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
    +            String networkUuid = implemented.getUuid();
    +            String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    +            String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    +            implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    +            implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    +            //Check if the network is associated to a VPC
    +            Long vpcId = network.getVpcId();
    +            boolean isVpc = (vpcId != null);
    +            //Check owner of the Network
    +            Domain networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    +            if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                String errorMessage = "CS project support is not yet implemented in NuageVsp";
    +                if (s_logger.isDebugEnabled()) {
    --- End diff --
    
    Why not log to ``ERROR`` instead of ``DEBUG`` as it appears that this condition has halted processing?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39895353
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyAclRuleVspCommand.java ---
    @@ -19,31 +19,45 @@
     
     package com.cloud.agent.api.element;
     
    +import com.cloud.agent.api.Command;
    +
     import java.util.List;
     import java.util.Map;
     
    -import com.cloud.agent.api.Command;
    -
     public class ApplyAclRuleVspCommand extends Command {
     
    +    boolean _networkAcl;
         String _networkUuid;
         String _networkDomainUuid;
         String _vpcOrSubnetUuid;
    -    boolean _isL3Network;
    +    String _networkName;
    +    boolean _isL2Network;
         List<Map<String, Object>> _aclRules;
    -    boolean _isVpc;
         long _networkId;
    +    boolean _egressDefaultPolicy;
    +    Boolean _acsIngressAcl;
    +    boolean _networkReset;
    +    String _domainTemplateName;
    --- End diff --
    
    Why aren't these attributes declared ``private``?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093221
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java ---
    @@ -48,13 +53,93 @@ public boolean isL3Network() {
             return _isL3Network;
         }
     
    +    public boolean isSharedNetwork() {
    +        return _isSharedNetwork;
    +    }
    +
         public String getVpcUuid() {
             return _vpcUuid;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<TrashNetworkVspCommand> {
    +        private String _domainUuid;
    +        private String _networkUuid;
    +        private boolean _isL3Network;
    +        private boolean _isSharedNetwork;
    +        private String _vpcUuid;
    +        private String _domainTemplateName;
    +
    +        public Builder domainUuid(String domainUuid) {
    +            this._domainUuid = domainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public TrashNetworkVspCommand build() {
    +            return new TrashNetworkVspCommand(_domainUuid, _networkUuid, _isL3Network, _isSharedNetwork, _vpcUuid, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    Implemented <code>equals</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41972314
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyAclRuleVspCommand.java ---
    @@ -79,4 +191,47 @@ public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ApplyAclRuleVspCommand that = (ApplyAclRuleVspCommand) o;
    +
    +        if (_egressDefaultPolicy != that._egressDefaultPolicy) return false;
    +        if (_isL2Network != that._isL2Network) return false;
    +        if (_networkAcl != that._networkAcl) return false;
    +        if (_networkId != that._networkId) return false;
    +        if (_networkReset != that._networkReset) return false;
    +        if (_aclRules != null ? !_aclRules.equals(that._aclRules) : that._aclRules != null) return false;
    +        if (_acsIngressAcl != null ? !_acsIngressAcl.equals(that._acsIngressAcl) : that._acsIngressAcl != null)
    +            return false;
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
    +            return false;
    +        if (_networkName != null ? !_networkName.equals(that._networkName) : that._networkName != null) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = (_networkAcl ? 1 : 0);
    +        result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
    +        result = 31 * result + (_networkDomainUuid != null ? _networkDomainUuid.hashCode() : 0);
    +        result = 31 * result + (_vpcOrSubnetUuid != null ? _vpcOrSubnetUuid.hashCode() : 0);
    +        result = 31 * result + (_networkName != null ? _networkName.hashCode() : 0);
    +        result = 31 * result + (_isL2Network ? 1 : 0);
    +        result = 31 * result + (_aclRules != null ? _aclRules.hashCode() : 0);
    +        result = 31 * result + (int) (_networkId ^ (_networkId >>> 32));
    +        result = 31 * result + (_egressDefaultPolicy ? 1 : 0);
    +        result = 31 * result + (_acsIngressAcl != null ? _acsIngressAcl.hashCode() : 0);
    +        result = 31 * result + (_networkReset ? 1 : 0);
    +        result = 31 * result + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43044473
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +441,22 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
     
             if (allIPsInCidr.size() > 3) {
    +            //get the second IP and see if it the networks GatewayIP
                 Iterator<Long> ipIterator = allIPsInCidr.iterator();
                 long vip = ipIterator.next();
    --- End diff --
    
    @nlivens what status of addressing this bit of feedback?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43052473
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -285,60 +529,334 @@ 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 (!Strings.isNullOrEmpty(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.error("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) {
    +                SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), add, remove);
    +                SyncDomainAnswer answer = (SyncDomainAnswer) _agentMgr.easySend(host.getId(), cmd);
    +                return answer.getSuccess();
    +            }
    +        }
    +        return true;
    +    }
     
    -        private String nuageVspEntity;
    +    private String findNuageVspCmsIdForDevice(long deviceId, ConfigurationVO cmsIdConfig) {
    +        String configValue = cmsIdConfig.getValue();
    +        if (!Strings.isNullOrEmpty(configValue)) {
    +            String[] configuredNuageVspDevices = configValue.split(";");
    +            for (String configuredNuageVspDevice : configuredNuageVspDevices) {
    +                if (configuredNuageVspDevice.startsWith(deviceId + ":")) {
    +                    String[] split = configuredNuageVspDevice.split(":");
    +                    if (split.length != 2 || (split.length > 1 && Strings.isNullOrEmpty(split[1]))) {
    +                        throw new IllegalArgumentException("The configured CMS ID for Nuage VSP device " + deviceId + " is in an incorrect format");
    +                    }
    +                    return split[1];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            if (configureExternalDns) {
    +                if (!Strings.isNullOrEmpty(dc.getDns1())) {
    +                    dnsServers.add(dc.getDns1());
    +                }
    +                if (!Strings.isNullOrEmpty(dc.getDns2())) {
    +                    dnsServers.add(dc.getDns2());
    +                }
    +            } else {
    +                if (!Strings.isNullOrEmpty(dc.getInternalDns1())) {
    +                    dnsServers.add(dc.getInternalDns1());
    +                }
    +                if (!Strings.isNullOrEmpty(dc.getInternalDns2())) {
    +                    dnsServers.add(dc.getInternalDns2());
    +                }
    +            }
             }
    +        return dnsServers;
    +    }
     
    -        public String getNuageVspEntity() {
    -            return nuageVspEntity;
    +    public List<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (!Strings.isNullOrEmpty(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(tokens.countTokens());
    +            while (tokens.hasMoreTokens())
    +            {
    +                gatewayIds.add(tokens.nextToken());
    +            }
             }
    +        return gatewayIds;
    +    }
     
    -        @Override
    -        public void run() {
    -            nuageVspSync.syncWithNuageVsp(nuageVspEntity);
    +    @Override
    +    public boolean preStateTransitionEvent(Status oldState, Status.Event event, Status newState, Host host, boolean status, Object opaque) {
    +        return true;
    +    }
    +
    +    @Override
    +    public boolean postStateTransitionEvent(StateMachine2.Transition<Status, Status.Event> 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<String, Object> 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<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
    +                    for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
    +                        HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
    --- End diff --
    
    Can a join be implemented on the DAO to retrieve the hosts?  A ``for`` loop of selects can put unnecessary strain on the database.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41980525
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -447,13 +568,95 @@ protected boolean applyACLRules(Network network, List<? extends InternalIdentity
                 }
     
             } catch (Exception e1) {
    --- End diff --
    
    Removed the <code>try {} catch () {}</code> block since it didn't add any value


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41806320
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -437,31 +463,79 @@ private Answer executeRequest(SyncVspCommand cmd) {
                 _nuageVspSyncClient.syncWithNuageVsp(cmd.getNuageVspEntity());
                 return new SyncVspAnswer(cmd, true, "Synced " + cmd.getNuageVspEntity() + " in VSP");
             } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
                 return new SyncVspAnswer(cmd, e);
             }
         }
     
    +    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
    +                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
    +                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    +            } else if (cmd.getSyncType() == SyncType.REGISTER) {
    +                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
    +                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
    +            } else {
    +                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
    +                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
    +            }
    +        } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
    +            return new SyncNuageVspCmsIdAnswer(false, null, cmd.getSyncType());
    +        }
    +    }
    +
    +    private Answer executeRequest(SyncDomainCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomainUuid(), cmd.getDomainName(), cmd.getDomainPath(), cmd.isToAdd(), cmd.isToRemove());
    +            return new SyncDomainAnswer(success);
    +        } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
    --- End diff --
    
    Please add identifying information about Nuage VSP device to assist operational debugging.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41972301
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyStaticNatVspCommand.java ---
    @@ -51,13 +61,91 @@ public boolean isL3Network() {
             return _isL3Network;
         }
     
    +    public boolean isVpc() {
    +        return _isVpc;
    +    }
    +
         public List<Map<String, Object>> getStaticNatDetails() {
             return _staticNatDetails;
         }
     
    +    public static class Builder extends CmdBuilder<ApplyStaticNatVspCommand> {
    +        private String _networkDomainUuid;
    +        private String _networkUuid;
    +        private String _vpcOrSubnetUuid;
    +        private boolean _isL3Network;
    +        private boolean _isVpc;
    +        private List<Map<String, Object>> _staticNatDetails;
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
    +            this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isVpc(boolean isVpc) {
    +            this._isVpc = isVpc;
    +            return this;
    +        }
    +
    +        public Builder staticNatDetails(List<Map<String, Object>> staticNatDetails) {
    +            this._staticNatDetails = staticNatDetails;
    +            return this;
    +        }
    +
    +        @Override
    +        public ApplyStaticNatVspCommand build() {
    +            return new ApplyStaticNatVspCommand(_networkDomainUuid, _networkUuid, _vpcOrSubnetUuid, _isL3Network, _isVpc, _staticNatDetails);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ApplyStaticNatVspCommand that = (ApplyStaticNatVspCommand) o;
    +
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isVpc != that._isVpc) return false;
    +        if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
    +            return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_staticNatDetails != null ? !_staticNatDetails.equals(that._staticNatDetails) : that._staticNatDetails != null)
    +            return false;
    +        if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _networkDomainUuid != null ? _networkDomainUuid.hashCode() : 0;
    +        result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
    +        result = 31 * result + (_vpcOrSubnetUuid != null ? _vpcOrSubnetUuid.hashCode() : 0);
    +        result = 31 * result + (_isL3Network ? 1 : 0);
    +        result = 31 * result + (_isVpc ? 1 : 0);
    +        result = 31 * result + (_staticNatDetails != null ? _staticNatDetails.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41805233
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -129,6 +145,18 @@
         AgentManager _agentMgr;
         @Inject
         NetworkOfferingDao _ntwkOfferingDao;
    +    @Inject
    +    ConfigurationDao _configDao;
    +    @Inject
    +    NuageVspManager _nuageVspManager;
    +    @Inject
    +    FirewallRulesDao _firewallRulesDao;
    +    @Inject
    +    FirewallRulesCidrsDao _firewallRulesCidrsDao;
    +    @Inject
    +    PhysicalNetworkDao _physicalNetworkDao;
    +    @Inject
    +    NetworkACLItemDao _networkACLItemDao;
     
         @Override
         public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> service) throws ResourceUnavailableException {
    --- End diff --
    
    Has any progress made on addressing this comment?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43104184
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -285,60 +529,334 @@ 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 (!Strings.isNullOrEmpty(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.error("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) {
    +                SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), add, remove);
    +                SyncDomainAnswer answer = (SyncDomainAnswer) _agentMgr.easySend(host.getId(), cmd);
    +                return answer.getSuccess();
    +            }
    +        }
    +        return true;
    +    }
     
    -        private String nuageVspEntity;
    +    private String findNuageVspCmsIdForDevice(long deviceId, ConfigurationVO cmsIdConfig) {
    +        String configValue = cmsIdConfig.getValue();
    +        if (!Strings.isNullOrEmpty(configValue)) {
    +            String[] configuredNuageVspDevices = configValue.split(";");
    +            for (String configuredNuageVspDevice : configuredNuageVspDevices) {
    +                if (configuredNuageVspDevice.startsWith(deviceId + ":")) {
    +                    String[] split = configuredNuageVspDevice.split(":");
    +                    if (split.length != 2 || (split.length > 1 && Strings.isNullOrEmpty(split[1]))) {
    +                        throw new IllegalArgumentException("The configured CMS ID for Nuage VSP device " + deviceId + " is in an incorrect format");
    +                    }
    +                    return split[1];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            if (configureExternalDns) {
    +                if (!Strings.isNullOrEmpty(dc.getDns1())) {
    +                    dnsServers.add(dc.getDns1());
    +                }
    +                if (!Strings.isNullOrEmpty(dc.getDns2())) {
    +                    dnsServers.add(dc.getDns2());
    +                }
    +            } else {
    +                if (!Strings.isNullOrEmpty(dc.getInternalDns1())) {
    +                    dnsServers.add(dc.getInternalDns1());
    +                }
    +                if (!Strings.isNullOrEmpty(dc.getInternalDns2())) {
    +                    dnsServers.add(dc.getInternalDns2());
    +                }
    +            }
             }
    +        return dnsServers;
    +    }
     
    -        public String getNuageVspEntity() {
    -            return nuageVspEntity;
    +    public List<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (!Strings.isNullOrEmpty(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(tokens.countTokens());
    +            while (tokens.hasMoreTokens())
    +            {
    +                gatewayIds.add(tokens.nextToken());
    +            }
             }
    +        return gatewayIds;
    +    }
     
    -        @Override
    -        public void run() {
    -            nuageVspSync.syncWithNuageVsp(nuageVspEntity);
    +    @Override
    +    public boolean preStateTransitionEvent(Status oldState, Status.Event event, Status newState, Host host, boolean status, Object opaque) {
    +        return true;
    +    }
    +
    +    @Override
    +    public boolean postStateTransitionEvent(StateMachine2.Transition<Status, Status.Event> 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<String, Object> 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<NuageVspDeviceVO> 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);
    +                    }
    +                } 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;
    +                List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
    +                for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
    +                    HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
    --- End diff --
    
    Yes, this is possible, but this means we would add a view to the DB, which would contain this join.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093062
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ImplementVspCommand.java ---
    @@ -0,0 +1,295 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.element;
    +
    +import com.cloud.agent.api.CmdBuilder;
    +import com.cloud.agent.api.Command;
    +
    +import java.util.List;
    +import java.util.Map;
    +
    +public class ImplementVspCommand extends Command {
    +
    +    private final long _networkId;
    +    private final String _networkDomainUuid;
    +    private final String _networkUuid;
    +    private final String _networkName;
    +    private final String _vpcOrSubnetUuid;
    +    private final boolean _isL2Network;
    +    private final boolean _isL3Network;
    +    private final boolean _isVpc;
    +    private final boolean _isShared;
    +    private final String _domainTemplateName;
    +    private final boolean _isFirewallServiceSupported;
    +    private final List<String> _dnsServers;
    +    private final List<Map<String, Object>> _ingressFirewallRules;
    +    private final List<Map<String, Object>> _egressFirewallRules;
    +    private final List<String> _acsFipUuid;
    +    private final boolean _egressDefaultPolicy;
    +
    +    private ImplementVspCommand(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
    +            boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
    +            List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) {
    +        super();
    +        this._networkId = networkId;
    +        this._networkDomainUuid = networkDomainUuid;
    +        this._networkUuid = networkUuid;
    +        this._networkName = networkName;
    +        this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +        this._isL2Network = isL2Network;
    +        this._isL3Network = isL3Network;
    +        this._isVpc = isVpc;
    +        this._isShared = isShared;
    +        this._domainTemplateName = domainTemplateName;
    +        this._isFirewallServiceSupported = isFirewallServiceSupported;
    +        this._dnsServers = dnsServers;
    +        this._ingressFirewallRules = ingressFirewallRules;
    +        this._egressFirewallRules = egressFirewallRules;
    +        this._acsFipUuid = acsFipUuid;
    +        this._egressDefaultPolicy = egressDefaultPolicy;
    +    }
    +
    +    public long getNetworkId() {
    +        return _networkId;
    +    }
    +
    +    public String getNetworkDomainUuid() {
    +        return _networkDomainUuid;
    +    }
    +
    +    public String getNetworkUuid() {
    +        return _networkUuid;
    +    }
    +
    +    public String getNetworkName() {
    +        return _networkName;
    +    }
    +
    +    public String getVpcOrSubnetUuid() {
    +        return _vpcOrSubnetUuid;
    +    }
    +
    +    public boolean isL2Network() {
    +        return _isL2Network;
    +    }
    +
    +    public boolean isL3Network() {
    +        return _isL3Network;
    +    }
    +
    +    public boolean isVpc() {
    +        return _isVpc;
    +    }
    +
    +    public boolean isShared() {
    +        return _isShared;
    +    }
    +
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public boolean isFirewallServiceSupported() {
    +        return _isFirewallServiceSupported;
    +    }
    +
    +    public List<String> getDnsServers() {
    +        return _dnsServers;
    +    }
    +
    +    public List<Map<String, Object>> getIngressFirewallRules() {
    +        return _ingressFirewallRules;
    +    }
    +
    +    public List<Map<String, Object>> getEgressFirewallRules() {
    +        return _egressFirewallRules;
    +    }
    +
    +    public List<String> getAcsFipUuid() {
    +        return _acsFipUuid;
    +    }
    +
    +    public boolean isEgressDefaultPolicy() {
    +        return _egressDefaultPolicy;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ImplementVspCommand> {
    +        private long _networkId;
    +        private String _networkDomainUuid;
    +        private String _networkUuid;
    +        private String _networkName;
    +        private String _vpcOrSubnetUuid;
    +        private boolean _isL2Network;
    +        private boolean _isL3Network;
    +        private boolean _isVpc;
    +        private boolean _isShared;
    +        private String _domainTemplateName;
    +        private boolean _isFirewallServiceSupported;
    +        private List<String> _dnsServers;
    +        private List<Map<String, Object>> _ingressFirewallRules;
    +        private List<Map<String, Object>> _egressFirewallRules;
    +        private List<String> _acsFipUuid;
    +        private boolean _egressDefaultPolicy;
    +
    +        public Builder networkId(long networkId) {
    +            this._networkId = networkId;
    +            return this;
    +        }
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder networkName(String networkName) {
    +            this._networkName = networkName;
    +            return this;
    +        }
    +
    +        public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
    +            this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +            return this;
    +        }
    +
    +        public Builder isL2Network(boolean isL2Network) {
    +            this._isL2Network = isL2Network;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isVpc(boolean isVpc) {
    +            this._isVpc = isVpc;
    +            return this;
    +        }
    +
    +        public Builder isShared(boolean isShared) {
    +            this._isShared = isShared;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        public Builder isFirewallServiceSupported(boolean isFirewallServiceSupported) {
    +            this._isFirewallServiceSupported = isFirewallServiceSupported;
    +            return this;
    +        }
    +
    +        public Builder dnsServers(List<String> dnsServers) {
    +            this._dnsServers = dnsServers;
    +            return this;
    +        }
    +
    +        public Builder ingressFirewallRules(List<Map<String, Object>> ingressFirewallRules) {
    +            this._ingressFirewallRules = ingressFirewallRules;
    +            return this;
    +        }
    +
    +        public Builder egressFirewallRules(List<Map<String, Object>> egressFirewallRules) {
    +            this._egressFirewallRules = egressFirewallRules;
    +            return this;
    +        }
    +
    +        public Builder acsFipUuid(List<String> acsFipUuid) {
    +            this._acsFipUuid = acsFipUuid;
    +            return this;
    +        }
    +
    +        public Builder egressDefaultPolicy(boolean egressDefaultPolicy) {
    +            this._egressDefaultPolicy = egressDefaultPolicy;
    +            return this;
    +        }
    +
    +        @Override
    +        public ImplementVspCommand build() {
    +            return new ImplementVspCommand(_networkId, _networkDomainUuid, _networkUuid, _networkName, _vpcOrSubnetUuid, _isL2Network, _isL3Network, _isVpc, _isShared,
    +                    _domainTemplateName, _isFirewallServiceSupported, _dnsServers, _ingressFirewallRules, _egressFirewallRules, _acsFipUuid, _egressDefaultPolicy);
    +        }
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ImplementVspCommand that = (ImplementVspCommand) o;
    +
    +        if (_egressDefaultPolicy != that._egressDefaultPolicy) return false;
    +        if (_isFirewallServiceSupported != that._isFirewallServiceSupported) return false;
    +        if (_isL2Network != that._isL2Network) return false;
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isShared != that._isShared) return false;
    +        if (_isVpc != that._isVpc) return false;
    +        if (_networkId != that._networkId) return false;
    +        if (_acsFipUuid != null ? !_acsFipUuid.equals(that._acsFipUuid) : that._acsFipUuid != null) return false;
    +        if (_dnsServers != null ? !_dnsServers.equals(that._dnsServers) : that._dnsServers != null) return false;
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_egressFirewallRules != null ? !_egressFirewallRules.equals(that._egressFirewallRules) : that._egressFirewallRules != null)
    +            return false;
    +        if (_ingressFirewallRules != null ? !_ingressFirewallRules.equals(that._ingressFirewallRules) : that._ingressFirewallRules != null)
    +            return false;
    +        if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
    +            return false;
    +        if (_networkName != null ? !_networkName.equals(that._networkName) : that._networkName != null) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by mlsorensen <gi...@git.apache.org>.
Github user mlsorensen commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-141502048
  
    LGTM


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093497
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncVspCommand.java ---
    @@ -39,4 +39,21 @@ public String getNuageVspEntity() {
             return _nuageVspEntity;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    Implemented <code>equals</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39896799
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/UpdateNuageVspDeviceCmd.java ---
    @@ -0,0 +1,180 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.api.commands;
    +
    +import com.cloud.api.response.NuageVspDeviceResponse;
    +import com.cloud.event.EventTypes;
    +import com.cloud.exception.ConcurrentOperationException;
    +import com.cloud.exception.InsufficientCapacityException;
    +import com.cloud.exception.InvalidParameterValueException;
    +import com.cloud.exception.ResourceAllocationException;
    +import com.cloud.exception.ResourceUnavailableException;
    +import com.cloud.network.NuageVspDeviceVO;
    +import com.cloud.network.manager.NuageVspManager;
    +import com.cloud.utils.exception.CloudRuntimeException;
    +import org.apache.cloudstack.api.APICommand;
    +import org.apache.cloudstack.api.ApiConstants;
    +import org.apache.cloudstack.api.ApiErrorCode;
    +import org.apache.cloudstack.api.BaseAsyncCmd;
    +import org.apache.cloudstack.api.BaseCmd;
    +import org.apache.cloudstack.api.Parameter;
    +import org.apache.cloudstack.api.ServerApiException;
    +import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
    +import org.apache.cloudstack.context.CallContext;
    +import org.apache.log4j.Logger;
    +
    +import javax.inject.Inject;
    +
    +@APICommand(name = "updateNuageVspDevice", responseObject = NuageVspDeviceResponse.class, description = "Update a Nuage VSP device")
    +public class UpdateNuageVspDeviceCmd extends BaseAsyncCmd {
    +    private static final Logger s_logger = Logger.getLogger(UpdateNuageVspDeviceCmd.class.getName());
    --- End diff --
    
    The class to ``getName()`` is not required -- ``Logger.getLogger()`` accepts a ``Class`` instance.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39900388
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -129,66 +131,97 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
     
         @Override
         public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    -
    -        assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    -
    -        long dcId = dest.getDataCenter().getId();
    -        //Get physical network id
    -        Long physicalNetworkId = network.getPhysicalNetworkId();
    -        //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    -        if (physicalNetworkId == null) {
    -            physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    -        }
    -        NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    -                network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    -        if (network.getGateway() != null) {
    -            implemented.setGateway(network.getGateway());
    -        }
    -        if (network.getCidr() != null) {
    -            implemented.setCidr(network.getCidr());
    -        }
    -        Collection<String> ipAddressRange = new ArrayList<String>();
    -        String virtualRouterIp = getVirtualRouterIP(network, ipAddressRange);
    -        String networkUuid = implemented.getUuid();
    -        String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    -        String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    -        implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    -        implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    -        //Check if the network is associated to a VPC
    -        Long vpcId = network.getVpcId();
    -        boolean isVpc = (vpcId != null);
    -        //Check owner of the Network
    -        Domain networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    -        if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            String errorMessage = "CS project support is not yet implemented in NuageVsp";
    -            s_logger.debug(errorMessage);
    -            throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
    -        }
    -        boolean isL3Network = isL3Network(offering.getId());
    -        String vpcName = null;
    -        String vpcUuid = null;
    -        if (isVpc) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcName = vpcObj.getName();
    -            vpcUuid = vpcObj.getUuid();
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(network.getId(), 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
             }
     
    -        HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
    -        ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(networksDomain.getName(), networksDomain.getPath(), networksDomain.getUuid(),
    -                networksAccount.getAccountName(), networksAccount.getUuid(), network.getName(), network.getCidr(), network.getGateway(), network.getUuid(), isL3Network, vpcName,
    -                vpcUuid, offering.getEgressDefaultPolicy(), ipAddressRange);
    -        ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +        NetworkVO implemented = null;
    +        try {
    +            assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +
    +            long dcId = dest.getDataCenter().getId();
    +            //Get physical network id
    +            Long physicalNetworkId = network.getPhysicalNetworkId();
    +            //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    +            if (physicalNetworkId == null) {
    +                physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    +            }
    +            implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    +                    network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    +            if (network.getGateway() != null) {
    +                implemented.setGateway(network.getGateway());
    +            }
    +            if (network.getCidr() != null) {
    +                implemented.setCidr(network.getCidr());
    +            }
    +            Collection<String[]> ipAddressRanges = new ArrayList<String[]>();
    --- End diff --
    
    Why is this variable declared as a ``Collection`` and not a ``List``?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39901809
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -201,51 +234,82 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil
         @Override
         public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
                 throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    -        nic.setBroadcastUri(network.getBroadcastUri());
    -        nic.setIsolationUri(network.getBroadcastUri());
    -
    -        s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    -        DataCenter dc = _dcDao.findById(network.getDataCenterId());
    -        Account networksAccount = _accountDao.findById(network.getAccountId());
    -        DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        long networkOwnedBy = network.getAccountId();
    -        AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    -        if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
             }
     
    -        //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    -        //that we create in VSP
    -        NicVO nicFrmDB = _nicDao.findById(nic.getId());
    -        long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
    -        boolean isL3Network = isL3Network(networkOfferingId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    -        }
    -        HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -        ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(nicFrmDB.getUuid(), nic.getMacAddress(), network.getUuid(), isL3Network, vpcUuid,
    -                networksDomain.getUuid(), networksAccount.getUuid(), vm.getType().equals(VirtualMachine.Type.DomainRouter), network.getBroadcastUri().getPath().substring(1),
    -                vm.getInstanceName(), vm.getUuid(), networksDomain.getUuid(), networksAccount.getUuid());
    -        ReserveVmInterfaceVspAnswer answer = (ReserveVmInterfaceVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ReserveVmInterfaceNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +        try {
    +            nic.setBroadcastUri(network.getBroadcastUri());
    +            nic.setIsolationUri(network.getBroadcastUri());
    +
    +            s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    +            DataCenter dc = _dcDao.findById(network.getDataCenterId());
    +            Account networksAccount = _accountDao.findById(network.getAccountId());
    +            DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            long networkOwnedBy = network.getAccountId();
    +            AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    +            if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    --- End diff --
    
    Why are two constant strings being concatenated here?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093300
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java ---
    @@ -0,0 +1,79 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Answer;
    +
    +import java.util.Map;
    +
    +public class GetClientDefaultsAnswer extends Answer {
    +
    +    private String _currentApiVersion;
    +    private Integer _apiRetryCount;
    +    private Long _apiRetryInterval;
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Map<String, Object> defaults) {
    +        super(cmd);
    +        this._currentApiVersion = (String) defaults.get("CURRENT_API_VERSION");
    +        this._apiRetryCount = (Integer) defaults.get("DEFAULT_API_RETRY_COUNT");
    +        this._apiRetryInterval = (Long) defaults.get("DEFAULT_API_RETRY_INTERVAL");
    +    }
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Exception e) {
    +        super(cmd, e);
    +    }
    +
    +    public String getCurrentApiVersion() {
    +        return _currentApiVersion;
    +    }
    +
    +    public Integer getApiRetryCount() {
    +        return _apiRetryCount;
    +    }
    +
    +    public Long getApiRetryInterval() {
    +        return _apiRetryInterval;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    Implemented <code>equals</code> method for the <code>Answer</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093086
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ShutDownVpcVspCommand.java ---
    @@ -40,9 +43,61 @@ public String getVpcUuid() {
             return _vpcUuid;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ShutDownVpcVspCommand> {
    +        private String _domainUuid;
    +        private String _vpcUuid;
    +        private String _domainTemplateName;
    +
    +        public Builder domainUuid(String domainUuid) {
    +            this._domainUuid = domainUuid;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public ShutDownVpcVspCommand build() {
    +            return new ShutDownVpcVspCommand(_domainUuid, _vpcUuid, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ShutDownVpcVspCommand that = (ShutDownVpcVspCommand) o;
    +
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
    +        if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41990160
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspGuruClient.java ---
    @@ -21,24 +21,22 @@
     
     import java.util.Collection;
     import java.util.List;
    -import java.util.Map;
     
     public interface NuageVspGuruClient {
     
    -    public void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
    -            String networkCidr, String networkGateway, String networkUuid, boolean isL3Network, String vpcName, String vpcUuid, boolean defaultEgressPolicy,
    -            Collection<String> ipAddressRange) throws Exception;
    +    void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
    +                          String networkCidr, String networkGateway, Long networkAclId, List<String> dnsServers, List<String> gatewaySystemIds, boolean isL3Network, boolean isVpc, boolean isSharedNetwork,
    +                          String networkUuid, String vpcName, String vpcUuid, boolean defaultEgressPolicy, Collection<String[]> ipAddressRange, String domainTemplateName) throws Exception;
    --- End diff --
    
    This is how the methods are declared in our client. They need to have the same signature as defined in our client.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39903296
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +441,22 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
     
             if (allIPsInCidr.size() > 3) {
    +            //get the second IP and see if it the networks GatewayIP
                 Iterator<Long> ipIterator = allIPsInCidr.iterator();
                 long vip = ipIterator.next();
    --- End diff --
    
    This logic appears to assume element order on a ``Set`` which provides no guarantees regarding the ordering of elements.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39899414
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -395,31 +510,23 @@ public IpDeployer getIpDeployer(Network network) {
     
         @Override
         public boolean applyFWRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
    -        s_logger.debug("Handling applyFWRules for network " + network.getName() + " with " + rules.size() + " FWRules");
    -        if (rules != null && rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
    +        if (rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
                 s_logger.debug("Default ACL added by CS as system is ignored for network " + network.getName() + " with rule " + rules);
                 return true;
             }
    -        return applyACLRules(network, rules, false);
    -    }
     
    -    @Override
    -    public boolean applyNetworkACLs(Network network, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
    -        if (rules == null || rules.isEmpty()) {
    -            s_logger.debug("No rules to apply. So, delete all the existing ACL in VSP from Subnet with uuid " + network.getUuid());
    -        } else {
    -            s_logger.debug("New rules has to applied. So, delete all the existing ACL in VSP from Subnet with uuid " + network.getUuid());
    -        }
    -        if (rules != null) {
    -            s_logger.debug("Handling applyNetworkACLs for network " + network.getName() + " with " + rules.size() + " Network ACLs");
    -            applyACLRules(network, rules, true);
    +        if (rules.isEmpty()) {
    +            return true;
             }
    -        return true;
    +
    +        s_logger.debug("Handling applyFWRules for network " + network.getName() + " with " + rules.size() + " FWRules");
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39896636
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/AddNuageVspDeviceCmd.java ---
    @@ -41,6 +29,17 @@
     import com.cloud.network.NuageVspDeviceVO;
     import com.cloud.network.manager.NuageVspManager;
     import com.cloud.utils.exception.CloudRuntimeException;
    +import org.apache.cloudstack.api.APICommand;
    +import org.apache.cloudstack.api.ApiConstants;
    +import org.apache.cloudstack.api.ApiErrorCode;
    +import org.apache.cloudstack.api.BaseAsyncCmd;
    +import org.apache.cloudstack.api.BaseCmd;
    +import org.apache.cloudstack.api.Parameter;
    +import org.apache.cloudstack.api.ServerApiException;
    +import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
    +import org.apache.cloudstack.context.CallContext;
    +
    +import javax.inject.Inject;
     
     @APICommand(name = "addNuageVspDevice", responseObject = NuageVspDeviceResponse.class, description = "Adds a Nuage VSP device")
    --- End diff --
    
    The ``since`` attribute should be declared on all ``APICommand``s for clearer documentation.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39907773
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspManagerClient.java ---
    @@ -0,0 +1,41 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package net.nuage.vsp.acs.client;
    +
    +import org.apache.commons.lang3.tuple.Pair;
    +
    +import java.util.Map;
    +
    +public interface NuageVspManagerClient {
    +
    +    public Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws Exception;
    +
    +    public String registerNuageVspCmsId() throws Exception;
    +
    +    public boolean unregisterNuageVspCmsId(String nuageVspCmsId) throws Exception;
    +
    +    public boolean isSupportedApiVersion(String version);
    +
    +    public Map<String, Object> getClientDefaults() throws Exception;
    +
    +    public boolean syncDomainWithNuageVsp(String domainUuid, String domainName, String domainPath, boolean add, boolean remove) throws Exception;
    +
    +    public <C extends NuageVspApiClient> void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
    --- End diff --
    
    Why is Exception declared in the throws instead of the list of expected checked exceptions on all of these methods?
    
    Also, ``public`` modifiers on ``public interface`` declarations are extraneous. 


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43027769
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyAclRuleVspCommand.java ---
    @@ -58,20 +73,117 @@ public String getVpcOrSubnetUuid() {
             return _vpcOrSubnetUuid;
         }
     
    -    public boolean isL3Network() {
    -        return _isL3Network;
    +    public String getNetworkName() {
    +        return _networkName;
    +    }
    +
    +    public boolean isL2Network() {
    +        return _isL2Network;
         }
     
         public List<Map<String, Object>> getAclRules() {
             return _aclRules;
         }
     
    -    public boolean isVpc() {
    -        return _isVpc;
    +    public long getNetworkId() {
    +        return _networkId;
         }
     
    -    public long getNetworkId() {
    -        return this._networkId;
    +    public boolean isEgressDefaultPolicy() {
    +        return _egressDefaultPolicy;
    +    }
    +
    +    public Boolean getAcsIngressAcl() {
    +        return _acsIngressAcl;
    +    }
    +
    +    public boolean isNetworkReset() {
    +        return _networkReset;
    +    }
    +
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ApplyAclRuleVspCommand> {
    --- End diff --
    
    Should some or all of the builder's attributes be set to reasonable defaults?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by runseb <gi...@git.apache.org>.
Github user runseb commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-154335646
  
    ok so bottom line, it seems reviews are +1 and we will merge this in 4.7.
    ASAP after 4.6.0 is out, taking.
    
    the only thing will be to keep an eye on it and rebase.
    
    unfortunately we cannot tag/label it for triaging properly.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41780153
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -122,13 +213,13 @@
             cmdList.add(DeleteNuageVspDeviceCmd.class);
             cmdList.add(ListNuageVspDevicesCmd.class);
             cmdList.add(IssueNuageVspResourceRequestCmd.class);
    -
    +        cmdList.add(UpdateNuageVspDeviceCmd.class);
    --- End diff --
    
    Consider using ``com.google.guava.collect.Lists#newHashMap`` for a more succinct way to build the list.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by KrisSterckx <gi...@git.apache.org>.
Github user KrisSterckx commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-153373302
  
    @jburwell we have added unit testing and Marvin tests, and we posted the results of Marvin in the Jira ticket, but in order to run the Marvin tests you need a Nuage VSP solution. I believe that was made clear and it is also @remibergsma 's understanding as we talked in Dublin.
    Having that said I do understand your request, and we can work at facilitating more community testing in next releases. Also we can certainly have the conversation on how we can help you on the short hand, or we could organize a live demo of the functionality or whatever helps in building trust. Thanks.



---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031755
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainCommand.java ---
    @@ -0,0 +1,91 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Command;
    +
    +public class SyncDomainCommand extends Command {
    +
    +    private final String _domainUuid;
    +    private final String _domainName;
    +    private final String _domainPath;
    +    private final boolean _toAdd;
    +    private final boolean _toRemove;
    +
    +    public SyncDomainCommand(String domainUuid, String domainName, String domainPath, boolean toAdd, boolean toRemove) {
    +        super();
    +        this._domainUuid = domainUuid;
    +        this._domainName = domainName;
    +        this._domainPath = domainPath;
    +        this._toAdd = toAdd;
    +        this._toRemove = toRemove;
    +    }
    +
    +    public String getDomainUuid() {
    +        return _domainUuid;
    +    }
    +
    +    public String getDomainName() {
    +        return _domainName;
    +    }
    +
    +    public String getDomainPath() {
    +        return _domainPath;
    +    }
    +
    +    public boolean isToAdd() {
    +        return _toAdd;
    +    }
    +
    +    public boolean isToRemove() {
    +        return _toRemove;
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncDomainCommand that = (SyncDomainCommand) o;
    +
    +        if (_toAdd != that._toAdd) return false;
    +        if (_toRemove != that._toRemove) return false;
    +        if (_domainName != null ? !_domainName.equals(that._domainName) : that._domainName != null) return false;
    +        if (_domainPath != null ? !_domainPath.equals(that._domainPath) : that._domainPath != null) return false;
    +        if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    This ``hashCode`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41803966
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        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"))) {
    +            paramsTobeUpdated.put("retryinterval", String.valueOf(command.getApiRetryInterval()));
    +        }
     
    -                        return nuageVspDevice;
    +        if (!paramsTobeUpdated.isEmpty()) {
    +            Map<String, String> latestParamsValue = new HashMap<String, String>();
    +            latestParamsValue.putAll(nuageVspHost.getDetails());
    +            latestParamsValue.putAll(paramsTobeUpdated);
    +            Map<String, Object> hostdetails = new HashMap<String, Object>(latestParamsValue);
    +
    +            try {
    +                resource.configure("", hostdetails);
    +                UpdateNuageVspDeviceCommand cmd = new UpdateNuageVspDeviceCommand(latestParamsValue);
    +                UpdateNuageVspDeviceAnswer answer = (UpdateNuageVspDeviceAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +                if (answer == null || !answer.getResult()) {
    +                    s_logger.error("UpdateNuageVspDeviceCommand failed");
    +                    if ((null != answer) && (null != answer.getDetails())) {
    +                        throw new CloudRuntimeException(answer.getDetails());
                         }
    -                });
    -            } else {
    -                throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
    +                }
    +                _hostDetailsDao.persist(nuageVspDevice.getHostId(), paramsTobeUpdated);
    +            } catch (Exception e) {
    --- End diff --
    
    Why are all checked and unchecked exceptions being caught here?  Why not catch the subset of expected checked exceptions?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41983983
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -129,66 +134,94 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
     
         @Override
         public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(network.getId(), 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
    +        }
     
    -        assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +        NetworkVO implemented = null;
    +        try {
    +            assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +
    +            long dcId = dest.getDataCenter().getId();
    +            //Get physical network id
    +            Long physicalNetworkId = network.getPhysicalNetworkId();
    +            //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    +            if (physicalNetworkId == null) {
    +                physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    +            }
    +            implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    +                    network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    +            if (network.getGateway() != null) {
    +                implemented.setGateway(network.getGateway());
    +            }
    +            if (network.getCidr() != null) {
    +                implemented.setCidr(network.getCidr());
    +            }
    +            List<String[]> ipAddressRanges = new ArrayList<String[]>();
    +            String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
    +            String networkUuid = implemented.getUuid();
    +            String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    +            String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    +            implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    +            implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    +            //Check if the network is associated to a VPC
    +            Long vpcId = network.getVpcId();
    +            boolean isVpc = (vpcId != null);
    +            //Check owner of the Network
    +            Domain networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    +            if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                String errorMessage = "CS project support is not yet implemented in NuageVsp";
    +                if (s_logger.isDebugEnabled()) {
    +                    s_logger.debug(errorMessage);
    +                }
    +                throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
    +            }
    +            String vpcName = null;
    +            String vpcUuid = null;
    +            String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
    +            boolean isSharedNetwork = offering.getGuestType() == GuestType.Shared;
    +            boolean isL3Network = !isVpc && (isSharedNetwork || isL3Network(network));
     
    -        long dcId = dest.getDataCenter().getId();
    -        //Get physical network id
    -        Long physicalNetworkId = network.getPhysicalNetworkId();
    -        //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    -        if (physicalNetworkId == null) {
    -            physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    -        }
    -        NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    -                network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    -        if (network.getGateway() != null) {
    -            implemented.setGateway(network.getGateway());
    -        }
    -        if (network.getCidr() != null) {
    -            implemented.setCidr(network.getCidr());
    -        }
    -        Collection<String> ipAddressRange = new ArrayList<String>();
    -        String virtualRouterIp = getVirtualRouterIP(network, ipAddressRange);
    -        String networkUuid = implemented.getUuid();
    -        String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    -        String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    -        implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    -        implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    -        //Check if the network is associated to a VPC
    -        Long vpcId = network.getVpcId();
    -        boolean isVpc = (vpcId != null);
    -        //Check owner of the Network
    -        Domain networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    -        if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            String errorMessage = "CS project support is not yet implemented in NuageVsp";
    -            s_logger.debug(errorMessage);
    -            throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
    -        }
    -        boolean isL3Network = isL3Network(offering.getId());
    -        String vpcName = null;
    -        String vpcUuid = null;
    -        if (isVpc) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcName = vpcObj.getName();
    -            vpcUuid = vpcObj.getUuid();
    -        }
    +            if (isVpc) {
    +                Vpc vpcObj = _vpcDao.findById(vpcId);
    +                vpcName = vpcObj.getName();
    +                vpcUuid = vpcObj.getUuid();
    +            }
    +
    +            if (isSharedNetwork) {
    +                List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
    +                for (VlanVO vlan : vlans) {
    +                    boolean isIpv4 = StringUtils.isNotBlank(vlan.getIpRange());
    +                    String[] range = isIpv4 ? vlan.getIpRange().split("-") : vlan.getIp6Range().split("-");
    +                    ipAddressRanges.add(range);
    +                }
    +            }
     
    -        HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
    -        ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(networksDomain.getName(), networksDomain.getPath(), networksDomain.getUuid(),
    -                networksAccount.getAccountName(), networksAccount.getUuid(), network.getName(), network.getCidr(), network.getGateway(), network.getUuid(), isL3Network, vpcName,
    -                vpcUuid, offering.getEgressDefaultPolicy(), ipAddressRange);
    -        ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +            HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
    +            List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +            List<String> gatewaySystemIds = _nuageVspManager.getGatewaySystemIds();
    +            ImplementNetworkVspCommand.Builder cmdBuilder = new ImplementNetworkVspCommand.Builder().networkDomainName(networksDomain.getName()).networkDomainPath(networksDomain.getPath())
    +                    .networkDomainUuid(networksDomain.getUuid()).networkAccountName(networksAccount.getAccountName()).networkAccountUuid(networksAccount.getUuid())
    +                    .networkName(network.getName()).networkCidr(network.getCidr()).networkGateway(network.getGateway()).networkAclId(network.getNetworkACLId()).dnsServers(dnsServers)
    +                    .gatewaySystemIds(gatewaySystemIds).networkUuid(network.getUuid()).isL3Network(isL3Network).isVpc(isVpc).isSharedNetwork(isSharedNetwork).vpcName(vpcName)
    +                    .vpcUuid(vpcUuid).defaultEgressPolicy(offering.getEgressDefaultPolicy()).ipAddressRange(ipAddressRanges).domainTemplateName(preConfiguredDomainTemplateName);
    +            ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
     
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ImplementNetworkNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +            if (answer == null || !answer.getResult()) {
    +                s_logger.error("ImplementNetworkNuageVspCommand failed");
    --- End diff --
    
    Added context information to the log statement.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093875
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -303,13 +414,17 @@ protected boolean canHandle(Network network, Service service) {
             }
     
             if (!_networkModel.isProviderForNetwork(getProvider(), network.getId())) {
    -            s_logger.debug("NuageElement is not a provider for network " + network.getDisplayText());
    +            if (s_logger.isDebugEnabled()) {
    +                s_logger.debug("NuageVsp is not a provider for network " + network.getDisplayText());
    --- End diff --
    
    This code is just checking whether NuageVsp is included as provider for the given network, no need for specific information about the Nuage VSP.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39898871
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -196,6 +227,20 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
                 ResourceUnavailableException, InsufficientCapacityException {
             s_logger.debug("Entering NuageElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
     
    +        if (network.getVpcId() != null) {
    +            List<NetworkACLItemVO> rules;
    +            if (network.getNetworkACLId() != null) {
    +                rules = _networkACLItemDao.listByACL(network.getNetworkACLId());
    +            } else {
    +                rules = new ArrayList<NetworkACLItemVO>(1);
    --- End diff --
    
    Why is a ``List`` of length 1 being created here?  If it should be empty, please use ``Collections.emptyList()``.  Otherwise, it feels like a leaking abstraction.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39902498
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -322,35 +383,57 @@ public void shutdown(NetworkProfile profile, NetworkOffering offering) {
     
         @Override
         public boolean trash(Network network, NetworkOffering offering) {
    -
    -        s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
    -        long domainId = network.getDomainId();
    -        Domain domain = _domainDao.findById(domainId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(networkId, 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
             }
    +
             try {
    -            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -            TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(domain.getUuid(), network.getUuid(), isL3Network(offering.getId()), vpcUuid);
    -            TrashNetworkVspAnswer answer = (TrashNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -            if (answer == null || !answer.getResult()) {
    -                s_logger.error("TrashNetworkNuageVspCommand for network " + network.getUuid() + " failed");
    -                if ((null != answer) && (null != answer.getDetails())) {
    -                    s_logger.error(answer.getDetails());
    +            s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776281
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ShutDownVpcVspCommand.java ---
    @@ -40,9 +43,61 @@ public String getVpcUuid() {
             return _vpcUuid;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder extends CmdBuilder<ShutDownVpcVspCommand> {
    +        private String _domainUuid;
    +        private String _vpcUuid;
    +        private String _domainTemplateName;
    +
    +        public Builder domainUuid(String domainUuid) {
    +            this._domainUuid = domainUuid;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public ShutDownVpcVspCommand build() {
    +            return new ShutDownVpcVspCommand(_domainUuid, _vpcUuid, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ShutDownVpcVspCommand that = (ShutDownVpcVspCommand) o;
    +
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
    +        if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _domainUuid != null ? _domainUuid.hashCode() : 0;
    +        result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
    +        result = 31 * result + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    Please implement ``toString()`` to provide debugging state information for debugging purposes.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39895255
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ImplementVspCommand.java ---
    @@ -0,0 +1,137 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.element;
    +
    +import com.cloud.agent.api.Command;
    +
    +import java.util.List;
    +import java.util.Map;
    +
    +public class ImplementVspCommand extends Command {
    +
    +    long _networkId;
    +    String _networkDomainUuid;
    +    String _networkUuid;
    +    String _networkName;
    +    String _vpcOrSubnetUuid;
    +    boolean _isL2Network;
    +    boolean _isL3Network;
    +    boolean _isVpc;
    +    boolean _isShared;
    +    String _domainTemplateName;
    +    boolean _isFirewallServiceSupported;
    +    List<String> _dnsServers;
    +    List<Map<String, Object>> _ingressFirewallRules;
    +    List<Map<String, Object>> _egressFirewallRules;
    +    List<String> _acsFipUuid;
    +    boolean _egressDefaultPolicy;
    --- End diff --
    
    Why aren't these attributes declared ``private``?  Also, why aren't they declared ``final`` since there are no setters declared?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39898784
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -196,6 +227,20 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
                 ResourceUnavailableException, InsufficientCapacityException {
             s_logger.debug("Entering NuageElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
    --- End diff --
    
    Wrap in a ``if (s_logger.isDebugEnabled()) { ... }`` block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776439
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyAclRuleVspAnswer.java ---
    @@ -31,4 +31,13 @@ public ApplyAclRuleVspAnswer(ApplyAclRuleVspCommand cmd, Exception e) {
             super(cmd, e);
         }
     
    +    @Override
    +    public boolean equals(Object obj) {
    +        return super.equals(obj);
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return super.hashCode();
    +    }
    --- End diff --
    
    Why does this class exist?  It adds no state or behavior to the ``Answer`` base class.  Why not simply use ``Answer`` in this circumstance?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41986950
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        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"))) {
    --- End diff --
    
    Moved the <code>Integer</code> parsing to a <code>final</code> local variable.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093227
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java ---
    @@ -48,13 +53,93 @@ public boolean isL3Network() {
             return _isL3Network;
         }
     
    +    public boolean isSharedNetwork() {
    +        return _isSharedNetwork;
    +    }
    +
         public String getVpcUuid() {
             return _vpcUuid;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<TrashNetworkVspCommand> {
    +        private String _domainUuid;
    +        private String _networkUuid;
    +        private boolean _isL3Network;
    +        private boolean _isSharedNetwork;
    +        private String _vpcUuid;
    +        private String _domainTemplateName;
    +
    +        public Builder domainUuid(String domainUuid) {
    +            this._domainUuid = domainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public TrashNetworkVspCommand build() {
    +            return new TrashNetworkVspCommand(_domainUuid, _networkUuid, _isL3Network, _isSharedNetwork, _vpcUuid, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        TrashNetworkVspCommand that = (TrashNetworkVspCommand) o;
    +
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isSharedNetwork != that._isSharedNetwork) return false;
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39902380
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -255,43 +319,22 @@ protected boolean canHandle(NetworkOffering offering, final NetworkType networkT
         }
     
         @Override
    -    public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
    -        long networkId = nic.getNetworkId();
    -        Network network = _networkDao.findById(networkId);
    -        s_logger.debug("Handling release() call back, which is called when a VM is stopped or destroyed, to delete the VM with state " + vm.getVirtualMachine().getState()
    -                + " from netork " + network.getName());
    -        if (vm.getVirtualMachine().getState().equals(VirtualMachine.State.Stopping)) {
    -            try {
    -                HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -                ReleaseVmVspCommand cmd = new ReleaseVmVspCommand(network.getUuid(), vm.getUuid(), vm.getInstanceName());
    -                ReleaseVmVspAnswer answer = (ReleaseVmVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -                if (answer == null || !answer.getResult()) {
    -                    s_logger.error("ReleaseVmNuageVspCommand for VM " + vm.getUuid() + " failed");
    -                    if ((null != answer) && (null != answer.getDetails())) {
    -                        s_logger.error(answer.getDetails());
    -                    }
    -                }
    -            } catch (InsufficientVirtualNetworkCapacityException e) {
    -                s_logger.debug("Handling release() call back. Failed to delete CS VM " + vm.getInstanceName() + " in VSP. " + e.getMessage());
    -            }
    -        } else {
    -            s_logger.debug("Handling release() call back. VM " + vm.getInstanceName() + " is in " + vm.getVirtualMachine().getState() + " state. So, the CS VM is not deleted."
    -                    + " This could be a case where VM interface is deleted. deallocate() call back should be called later");
    -        }
    -
    -        return super.release(nic, vm, reservationId);
    -    }
    -
    -    @Override
         @DB
         public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for deallocation of user VM " + vm.getInstanceName());
    +        }
     
             try {
                 s_logger.debug("Handling deallocate() call back, which is called when a VM is destroyed or interface is removed, " + "to delete VM Interface with IP "
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-141592925
  
    Is there a test plan/procedure for verifying the operation of his plugin?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41989984
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/NuageVspPluginClientLoader.java ---
    @@ -19,28 +19,86 @@
     
     package net.nuage.vsp.acs;
     
    +import net.nuage.vsp.acs.client.NuageVspApiClient;
    +import net.nuage.vsp.acs.client.NuageVspElementClient;
    +import net.nuage.vsp.acs.client.NuageVspGuruClient;
    +import net.nuage.vsp.acs.client.NuageVspManagerClient;
    +import net.nuage.vsp.acs.client.NuageVspSyncClient;
    +
     import java.net.MalformedURLException;
     import java.net.URL;
     import java.net.URLClassLoader;
     
     public class NuageVspPluginClientLoader {
     
    -    private static NuageVspPluginClientLoader nuageVspPluginClientClassloader;
    -    private ClassLoader loader = null;
    +    private ClassLoader _loader = null;
    +
    +    private NuageVspApiClient _nuageVspApiClient;
    +    private NuageVspElementClient _nuageVspElementClient;
    +    private NuageVspGuruClient _nuageVspGuruClient;
    +    private NuageVspManagerClient _nuageVspManagerClient;
    +    private NuageVspSyncClient _nuageVspSyncClient;
    +
    +    public static final String NUAGE_PLUGIN_CLIENT_JAR_FILE = "/usr/share/nuagevsp/lib/nuage-vsp-acs-client.jar";
    +    private static final String NUAGE_VSP_API_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspApiClientImpl";
    +    private static final String NUAGE_VSP_SYNC_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspSyncClientImpl";
    +    private static final String NUAGE_VSP_ELEMENT_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspElementClientImpl";
    +    private static final String NUAGE_VSP_GURU_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspGuruClientImpl";
    +    private static final String NUAGE_VSP_MANAGER_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspManagerClientImpl";
     
         private NuageVspPluginClientLoader(String nuagePluginClientJarLocation) {
             try {
    -            loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
    +            _loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
                         getClass().getClassLoader());
             } catch (MalformedURLException e) {
    -            e.printStackTrace();
    +            throw new IllegalArgumentException(e);
             }
         }
     
    -    public static ClassLoader getClassLoader(String nuagePluginClientJarLocation) {
    -        if (nuageVspPluginClientClassloader == null) {
    -            nuageVspPluginClientClassloader = new NuageVspPluginClientLoader(nuagePluginClientJarLocation);
    -        }
    -        return nuageVspPluginClientClassloader.loader;
    +    public static NuageVspPluginClientLoader getClientLoader(String relativePath, String[] cmsUserInfo, int numRetries, int retryInterval,
    +            String nuageVspCmsId) throws Exception {
    --- End diff --
    
    Removed the <code>throws Exception</code>.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by KrisSterckx <gi...@git.apache.org>.
Github user KrisSterckx commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-145488778
  
    I would like to bring attention to the reviewers that only a few CS core extensions were made - all other modifications are NuageVsp plugin internal, for Nuage Virtualized Services Platform Release 3.2 support.
    
    api/src/com/cloud/network/Network.java
    * Remove the unused NuageVspVpc constant
    
    engine/schema/src/com/cloud/network/dao/IPAddressDao.java
    engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
    * new DAO method added
    
    engine/schema/src/com/cloud/network/vpc/VpcOfferingVO.java
    * new constructor added
    
    server/src/com/cloud/configuration/ConfigurationManagerImpl.java
    * Exclude shared networks from DirectNetworkGuru canHandle() in case the offering is NuageVsp as then NuageVsp guru is handling.
    
    server/src/com/cloud/configuration/ConfigurationManagerImpl.java
    * Add extra check on isPersistent() for nuageVpc check


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by mlsorensen <gi...@git.apache.org>.
Github user mlsorensen commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-153863283
  
    John,
        I probably shouldn't respond in this thread, but from your response I
    feel like much of my point was missed. In fact I had pointed out the very
    thing you mention, that there's no requirement for third parties to submit
    their code to the community, they could ship their plugin standalone and
    have their users install it. If a user has a problem, it won't matter if
    the plugin was shipped with CloudStack or installed standalone, the result
    will be the same.
        I think we are in agreement that the code should have the same
    standards, but I think we (and I mean all of us) differ to varying degrees
    in what those standards should be. One may block an important commit
    because it uses String.length() == 0 instead of String.isEmpty(), or
    doesn't print enough debug info, and end up postponing the benefit of the
    fixes to the next release, while another committer might not care about
    that level of review and standard. There should probably be a basic list of
    items to look for so that the reviews themselves can be standardized. I
    think that would also address the concern I have for the community culture,
    because contributors will fear the review process less if they can see up
    front what the criteria are for merge. There's little I can think of that
    is more detrimental to growing our community of committers than making
    people feel like they're submitted to an arbitrary level of scrutiny
    whenever they contribute. When contributing becomes painful then we're held
    at arms length, rather than encouraging ownership of the code and
    participation.
    
    On Wed, Nov 4, 2015 at 10:35 AM, John Burwell <no...@github.com>
    wrote:
    
    > I agree with @runseb <https://github.com/runseb> that we need to move
    > this discussion to dev@, and re-assess accepting the maintenance
    > responsibly for code that cannot be tested and verified by the community.
    > This plugin has already been accepted into 4.5, and as such, would be
    > "grandfathered" into any decision we would make. Therefore, we should carry
    > our current precedent forward and not prevent acceptance of this PR for
    > this reason. We are at a point in the 4.6 release cycle that only blockers
    > should be accepted. Otherwise, we will never ship 4.6.
    >
    > @KrisSterckx <https://github.com/KrisSterckx> I realize my comments may
    > come across as unappreciative which is not my intention. I greatly
    > appreciate the work @nlivens <https://github.com/nlivens> and you have
    > done to contribute this capability to the community. This plugin highlights
    > a larger issue which is that, as a community, we are delivering releases
    > containing code that cannot be verified. By contributing this plugin to our
    > community, we become responsible for its support and maintenance. In 6-12
    > months, how do answer answer a user who asks does this plugin work in the
    > latest release if you are unavailable?
    >
    > @runseb <https://github.com/runseb> while there is a fairness issue for
    > the contributor, I think it is incredibly unfair to our users that we ship
    > code without on-going validation. When a user sees the availability of
    > PluginX supporting Device1 in a release, they assume that we have verified
    > the proper operation of PluginX since we shipped it in that release. In
    > fact, we haven't, and they may be attempting to use something that is
    > completely broken.
    >
    > @mlsorensen <https://github.com/mlsorensen> yes, plugins provide a
    > mechanism for vendors to extend CloudStack. However, there is no
    > requirement for those plugins to be part of the community, OSS codebase.
    > Therefore, we should not conflate the ability of third-parties to extend
    > CloudStack using plugins with the code that is accepted as part of the
    > community's repositories. All code in our repositories, regardless of being
    > in the core or a plugin, should be held to the same standards. When a user
    > has a problem, they aren't any less frustrated with the project because
    > their problem happens to be in a plugin.
    >
    > @mike-tutkowski <https://github.com/mike-tutkowski> I don't believe that
    > code inspection by itself is adequate to determine the quality of code
    > integrating an external device. For example, I reviewed the code for this
    > plugin, and while I feel confident that it will behave well within the
    > management server, I have absolutely no idea if the various network
    > functions are being properly automated using the Nuage client APIs. The
    > only way for those aspects of the plugin's operation to be verified would
    > be to run in a test environment with a Nuage device and realize a set of
    > network topologies.
    >
    > —
    > Reply to this email directly or view it on GitHub
    > <https://github.com/apache/cloudstack/pull/801#issuecomment-153822915>.
    >



---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43042002
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -205,6 +250,75 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
                 return false;
             }
     
    +        final boolean egressDefaultPolicy = offering.getEgressDefaultPolicy();
    +        Domain networkDomain = _domainDao.findById(network.getDomainId());
    +        boolean isFirewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.Firewall);
    +        List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +
    +        boolean isL2Network = false, isL3Network = false, isShared = false;
    +        String subnetUuid = network.getUuid();
    +        if (offering.getGuestType() == Network.GuestType.Shared) {
    +            isShared = true;
    +            subnetUuid = networkDomain.getUuid();
    +        } else if (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.StaticNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
    +            isL3Network = true;
    +        } else {
    +            isL2Network = true;
    +        }
    +
    +        String preConfiguredDomainTemplateName = getPreConfiguredDomainTemplateName(network, offering);
    +        List<FirewallRuleVO> firewallIngressRulesToApply =
    +                _firewallRulesDao.listByNetworkPurposeTrafficType(network.getId(), FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress);
    +        for (FirewallRuleVO rule : firewallIngressRulesToApply) {
    +            // load cidrs if any
    +            rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId()));
    +        }
    +
    +        List<FirewallRuleVO> firewallEgressRulesToApply =
    +                _firewallRulesDao.listByNetworkPurposeTrafficType(network.getId(), FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress);
    +        for (FirewallRuleVO rule : firewallEgressRulesToApply) {
    +            // load cidrs if any
    +            rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId()));
    +        }
    +
    +        List<Map<String, Object>> ingressFirewallRules = Lists.transform(firewallIngressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<Map<String, Object>> egressFirewallRules = Lists.transform(firewallEgressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    --- End diff --
    
    @nlivens Any updates on the status of addressing this comment?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41979466
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/DeallocateVmVspAnswer.java ---
    @@ -31,4 +31,14 @@ public DeallocateVmVspAnswer(Command command, Exception e) {
         public DeallocateVmVspAnswer(DeallocateVmVspCommand cmd, boolean success, String details) {
             super(cmd, success, details);
         }
    +
    +    @Override
    +    public boolean equals(Object obj) {
    +        return super.equals(obj);
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return super.hashCode();
    +    }
    --- End diff --
    
    Removed, using <code>Answer</code> base class instead


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-141986296
  
    @jburwell, I've commented on some of your comments, and I'm working on implementing the other comments


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41803659
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        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"))) {
    --- End diff --
    
    Extract the Integer parsing for a ``final`` local variable to make this ``if`` block easier to read/follow.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41779077
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -129,66 +134,94 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
     
         @Override
         public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(network.getId(), 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
    +        }
     
    -        assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +        NetworkVO implemented = null;
    +        try {
    +            assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +
    +            long dcId = dest.getDataCenter().getId();
    +            //Get physical network id
    +            Long physicalNetworkId = network.getPhysicalNetworkId();
    +            //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    +            if (physicalNetworkId == null) {
    +                physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    +            }
    +            implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    +                    network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    +            if (network.getGateway() != null) {
    +                implemented.setGateway(network.getGateway());
    +            }
    +            if (network.getCidr() != null) {
    +                implemented.setCidr(network.getCidr());
    +            }
    +            List<String[]> ipAddressRanges = new ArrayList<String[]>();
    +            String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
    +            String networkUuid = implemented.getUuid();
    +            String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    +            String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    +            implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    +            implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    +            //Check if the network is associated to a VPC
    +            Long vpcId = network.getVpcId();
    +            boolean isVpc = (vpcId != null);
    +            //Check owner of the Network
    +            Domain networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    +            if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                String errorMessage = "CS project support is not yet implemented in NuageVsp";
    +                if (s_logger.isDebugEnabled()) {
    +                    s_logger.debug(errorMessage);
    +                }
    +                throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
    +            }
    +            String vpcName = null;
    +            String vpcUuid = null;
    +            String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
    +            boolean isSharedNetwork = offering.getGuestType() == GuestType.Shared;
    +            boolean isL3Network = !isVpc && (isSharedNetwork || isL3Network(network));
     
    -        long dcId = dest.getDataCenter().getId();
    -        //Get physical network id
    -        Long physicalNetworkId = network.getPhysicalNetworkId();
    -        //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    -        if (physicalNetworkId == null) {
    -            physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    -        }
    -        NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    -                network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    -        if (network.getGateway() != null) {
    -            implemented.setGateway(network.getGateway());
    -        }
    -        if (network.getCidr() != null) {
    -            implemented.setCidr(network.getCidr());
    -        }
    -        Collection<String> ipAddressRange = new ArrayList<String>();
    -        String virtualRouterIp = getVirtualRouterIP(network, ipAddressRange);
    -        String networkUuid = implemented.getUuid();
    -        String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    -        String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    -        implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    -        implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    -        //Check if the network is associated to a VPC
    -        Long vpcId = network.getVpcId();
    -        boolean isVpc = (vpcId != null);
    -        //Check owner of the Network
    -        Domain networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    -        if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            String errorMessage = "CS project support is not yet implemented in NuageVsp";
    -            s_logger.debug(errorMessage);
    -            throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
    -        }
    -        boolean isL3Network = isL3Network(offering.getId());
    -        String vpcName = null;
    -        String vpcUuid = null;
    -        if (isVpc) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcName = vpcObj.getName();
    -            vpcUuid = vpcObj.getUuid();
    -        }
    +            if (isVpc) {
    +                Vpc vpcObj = _vpcDao.findById(vpcId);
    +                vpcName = vpcObj.getName();
    +                vpcUuid = vpcObj.getUuid();
    +            }
    +
    +            if (isSharedNetwork) {
    +                List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
    +                for (VlanVO vlan : vlans) {
    +                    boolean isIpv4 = StringUtils.isNotBlank(vlan.getIpRange());
    +                    String[] range = isIpv4 ? vlan.getIpRange().split("-") : vlan.getIp6Range().split("-");
    +                    ipAddressRanges.add(range);
    +                }
    +            }
     
    -        HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
    -        ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(networksDomain.getName(), networksDomain.getPath(), networksDomain.getUuid(),
    -                networksAccount.getAccountName(), networksAccount.getUuid(), network.getName(), network.getCidr(), network.getGateway(), network.getUuid(), isL3Network, vpcName,
    -                vpcUuid, offering.getEgressDefaultPolicy(), ipAddressRange);
    -        ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +            HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
    +            List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +            List<String> gatewaySystemIds = _nuageVspManager.getGatewaySystemIds();
    +            ImplementNetworkVspCommand.Builder cmdBuilder = new ImplementNetworkVspCommand.Builder().networkDomainName(networksDomain.getName()).networkDomainPath(networksDomain.getPath())
    +                    .networkDomainUuid(networksDomain.getUuid()).networkAccountName(networksAccount.getAccountName()).networkAccountUuid(networksAccount.getUuid())
    +                    .networkName(network.getName()).networkCidr(network.getCidr()).networkGateway(network.getGateway()).networkAclId(network.getNetworkACLId()).dnsServers(dnsServers)
    +                    .gatewaySystemIds(gatewaySystemIds).networkUuid(network.getUuid()).isL3Network(isL3Network).isVpc(isVpc).isSharedNetwork(isSharedNetwork).vpcName(vpcName)
    +                    .vpcUuid(vpcUuid).defaultEgressPolicy(offering.getEgressDefaultPolicy()).ipAddressRange(ipAddressRanges).domainTemplateName(preConfiguredDomainTemplateName);
    +            ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
     
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ImplementNetworkNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +            if (answer == null || !answer.getResult()) {
    +                s_logger.error("ImplementNetworkNuageVspCommand failed");
    --- End diff --
    
    Please provide context information about the Nuage device and network that failed to configure.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093140
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/DeallocateVmVspCommand.java ---
    @@ -83,9 +92,130 @@ public String getVmUuid() {
             return _vmUuid;
         }
     
    +    public boolean isExpungingState() {
    +        return _isExpungingState;
    +    }
    +
    +    public static class Builder implements CmdBuilder<DeallocateVmVspCommand> {
    +        private String _networkUuid;
    +        private String _nicFromDdUuid;
    +        private String _nicMacAddress;
    +        private String _nicIp4Address;
    +        private boolean _isL3Network;
    +        private boolean _isSharedNetwork;
    +        private String _vpcUuid;
    +        private String _networksDomainUuid;
    +        private String _vmInstanceName;
    +        private String _vmUuid;
    +        private boolean _isExpungingState;
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder nicFromDbUuid(String nicFromDbUuid) {
    +            this._nicFromDdUuid = nicFromDbUuid;
    +            return this;
    +        }
    +
    +        public Builder nicMacAddress(String nicMacAddress) {
    +            this._nicMacAddress = nicMacAddress;
    +            return this;
    +        }
    +
    +        public Builder nicIp4Address(String nicIp4Address) {
    +            this._nicIp4Address = nicIp4Address;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder networksDomainUuid(String networksDomainUuid) {
    +            this._networksDomainUuid = networksDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder vmInstanceName(String vmInstanceName) {
    +            this._vmInstanceName = vmInstanceName;
    +            return this;
    +        }
    +
    +        public Builder vmUuid(String vmUuid) {
    +            this._vmUuid = vmUuid;
    +            return this;
    +        }
    +
    +        public Builder isExpungingState(boolean isExpungingState) {
    +            this._isExpungingState = isExpungingState;
    +            return this;
    +        }
    +
    +        @Override
    +        public DeallocateVmVspCommand build() {
    +            return new DeallocateVmVspCommand(_networkUuid,_nicFromDdUuid, _nicMacAddress, _nicIp4Address, _isL3Network, _isSharedNetwork, _vpcUuid,
    +                    _networksDomainUuid, _vmInstanceName, _vmUuid, _isExpungingState);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        DeallocateVmVspCommand that = (DeallocateVmVspCommand) o;
    +
    +        if (_isExpungingState != that._isExpungingState) return false;
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isSharedNetwork != that._isSharedNetwork) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_networksDomainUuid != null ? !_networksDomainUuid.equals(that._networksDomainUuid) : that._networksDomainUuid != null)
    +            return false;
    +        if (_nicFromDdUuid != null ? !_nicFromDdUuid.equals(that._nicFromDdUuid) : that._nicFromDdUuid != null)
    +            return false;
    +        if (_nicIp4Address != null ? !_nicIp4Address.equals(that._nicIp4Address) : that._nicIp4Address != null)
    +            return false;
    +        if (_nicMacAddress != null ? !_nicMacAddress.equals(that._nicMacAddress) : that._nicMacAddress != null)
    +            return false;
    +        if (_vmInstanceName != null ? !_vmInstanceName.equals(that._vmInstanceName) : that._vmInstanceName != null)
    +            return false;
    +        if (_vmUuid != null ? !_vmUuid.equals(that._vmUuid) : that._vmUuid != null) return false;
    +        if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39962640
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +441,22 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
     
             if (allIPsInCidr.size() > 3) {
    +            //get the second IP and see if it the networks GatewayIP
                 Iterator<Long> ipIterator = allIPsInCidr.iterator();
                 long vip = ipIterator.next();
    --- End diff --
    
    True, but the NetUtils.getAllIpsFromCidr method returns a TreeSet which is an ordered Set


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43044620
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -201,51 +234,82 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil
         @Override
         public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
                 throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    -        nic.setBroadcastUri(network.getBroadcastUri());
    -        nic.setIsolationUri(network.getBroadcastUri());
    -
    -        s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    -        DataCenter dc = _dcDao.findById(network.getDataCenterId());
    -        Account networksAccount = _accountDao.findById(network.getAccountId());
    -        DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        long networkOwnedBy = network.getAccountId();
    -        AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    -        if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
             }
     
    -        //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    -        //that we create in VSP
    -        NicVO nicFrmDB = _nicDao.findById(nic.getId());
    -        long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
    -        boolean isL3Network = isL3Network(networkOfferingId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    -        }
    -        HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -        ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(nicFrmDB.getUuid(), nic.getMacAddress(), network.getUuid(), isL3Network, vpcUuid,
    -                networksDomain.getUuid(), networksAccount.getUuid(), vm.getType().equals(VirtualMachine.Type.DomainRouter), network.getBroadcastUri().getPath().substring(1),
    -                vm.getInstanceName(), vm.getUuid(), networksDomain.getUuid(), networksAccount.getUuid());
    -        ReserveVmInterfaceVspAnswer answer = (ReserveVmInterfaceVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ReserveVmInterfaceNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +        try {
    +            nic.setBroadcastUri(network.getBroadcastUri());
    +            nic.setIsolationUri(network.getBroadcastUri());
    +
    +            s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    +            DataCenter dc = _dcDao.findById(network.getDataCenterId());
    +            Account networksAccount = _accountDao.findById(network.getAccountId());
    +            DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            long networkOwnedBy = network.getAccountId();
    +            AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    +            if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +            }
    +
    +            //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    +            //that we create in VSP
    +            NicVO nicFrmDB = _nicDao.findById(nic.getId());
    +            NetworkOffering networkOffering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
    +            boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter);
    +            String domainRouterIp = network.getBroadcastUri().getPath().substring(1);
    --- End diff --
    
    @nlivens what's the status of addressing this bit of feedback?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-153473377
  
    @ustcweizhou @remibergsma this is a massive technical debt that we are carrying with other plugins, and I think we need to stop to expanding that debt.  In some cases, we (i.e. ASF) have been granted licenses for virtual appliances to test plugin operation (a completely valid way to verify operation).  For others, we are shipping code that has not been verified for a number of releases.  In the past, plugins have been contributed and tested for a release, but those contributors have not remained active to maintain the plugin.  Since the community lacks the equipment or test rigs, no one else can pick up maintenance -- leaving us with bit rotting code.  In summary, as a community, we should not be accepting the responsibility to support and maintain code whose operation we cannot verify -- plugin or core.  The question of what to do with existing plugins that don't meet this criteria is a discussion for another thread.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43052201
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -285,60 +529,334 @@ 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 (!Strings.isNullOrEmpty(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.error("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) {
    +                SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), add, remove);
    +                SyncDomainAnswer answer = (SyncDomainAnswer) _agentMgr.easySend(host.getId(), cmd);
    +                return answer.getSuccess();
    +            }
    +        }
    +        return true;
    +    }
     
    -        private String nuageVspEntity;
    +    private String findNuageVspCmsIdForDevice(long deviceId, ConfigurationVO cmsIdConfig) {
    +        String configValue = cmsIdConfig.getValue();
    +        if (!Strings.isNullOrEmpty(configValue)) {
    +            String[] configuredNuageVspDevices = configValue.split(";");
    +            for (String configuredNuageVspDevice : configuredNuageVspDevices) {
    +                if (configuredNuageVspDevice.startsWith(deviceId + ":")) {
    +                    String[] split = configuredNuageVspDevice.split(":");
    +                    if (split.length != 2 || (split.length > 1 && Strings.isNullOrEmpty(split[1]))) {
    +                        throw new IllegalArgumentException("The configured CMS ID for Nuage VSP device " + deviceId + " is in an incorrect format");
    +                    }
    +                    return split[1];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> dnsServers = null;
    +        Boolean configureDns = Boolean.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigDns.key()));
    +        if (configureDns) {
    --- End diff --
    
    To reduce method complexity, short-circuit the method if the ``configureDns`` list is empty by returning an empty list when it is false.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39905801
  
    --- 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];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            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<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (StringUtils.isNotBlank(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(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<Status, Status.Event> 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<String, Object> 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<NuageVspDeviceVO> 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<NuageVspDeviceVO> 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());
    --- End diff --
    
    Pass the exception instance into the logger to capture the full stack trace for debugging.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43104591
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -170,20 +169,18 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
                 throw new ConfigurationException("Unable to find retry interval");
             }
     
    -        _relativePath = new StringBuffer().append("https://").append(hostname).append(":").append(port).append(apiRelativePath).toString();
    +        _relativePath = new StringBuffer().append("https://").append(_hostName).append(":").append(port).append(apiRelativePath).toString();
     
             String cmsUserPass = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.decodeBase64(cmsUserPassBase64));
             _cmsUserInfo = new String[] {CMS_USER_ENTEPRISE_NAME, cmsUser, cmsUserPass};
     
    -        try {
    -            loadNuageClient();
    -        } catch (Exception e) {
    -            throw new CloudRuntimeException("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
    -        }
    +        _nuageVspCmsId = (String)params.get("nuagevspcmsid");
    +
    +        loadNuageClient();
     
             try {
                 login();
    -        } catch (Exception e) {
    +        } catch (ExecutionException | ConfigurationException e) {
                 s_logger.error("Failed to login to Nuage VSD on " + name + " as user " + cmsUser + " Exception " + e.getMessage());
    --- End diff --
    
    Done.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43092627
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/VspResourceCommand.java ---
    @@ -79,4 +79,41 @@ public String getProxyUserDomainuuid() {
         public boolean executeInSequence() {
             return false;
         }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        VspResourceCommand that = (VspResourceCommand) o;
    +
    +        if (_childResource != null ? !_childResource.equals(that._childResource) : that._childResource != null)
    +            return false;
    +        if (_entityDetails != null ? !_entityDetails.equals(that._entityDetails) : that._entityDetails != null)
    +            return false;
    +        if (_method != null ? !_method.equals(that._method) : that._method != null) return false;
    +        if (_proxyUserDomainuuid != null ? !_proxyUserDomainuuid.equals(that._proxyUserDomainuuid) : that._proxyUserDomainuuid != null)
    +            return false;
    +        if (_proxyUserUuid != null ? !_proxyUserUuid.equals(that._proxyUserUuid) : that._proxyUserUuid != null)
    +            return false;
    +        if (_resource != null ? !_resource.equals(that._resource) : that._resource != null) return false;
    +        if (_resourceFilter != null ? !_resourceFilter.equals(that._resourceFilter) : that._resourceFilter != null)
    +            return false;
    +        if (_resourceId != null ? !_resourceId.equals(that._resourceId) : that._resourceId != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41973455
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncVspCommand.java ---
    @@ -39,4 +39,21 @@ public String getNuageVspEntity() {
             return _nuageVspEntity;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncVspCommand that = (SyncVspCommand) o;
    +
    +        if (_nuageVspEntity != null ? !_nuageVspEntity.equals(that._nuageVspEntity) : that._nuageVspEntity != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return _nuageVspEntity != null ? _nuageVspEntity.hashCode() : 0;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41994074
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/UpdateNuageVspDeviceCommand.java ---
    @@ -0,0 +1,60 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api;
    +
    +import java.util.Collections;
    +import java.util.Map;
    +
    +public class UpdateNuageVspDeviceCommand extends Command {
    +
    +    private final Map<String, String> _parametersToBeUpdated;
    +
    +    public UpdateNuageVspDeviceCommand(Map<String, String> parametersToBeUpdated) {
    +        super();
    +        this._parametersToBeUpdated = parametersToBeUpdated;
    --- End diff --
    
    @nlivens nice


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39905503
  
    --- 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];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            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<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (StringUtils.isNotBlank(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(tokens.countTokens());
    +            while (tokens.hasMoreTokens())
    +            {
    +                gatewayIds.add(tokens.nextToken());
    +            }
    --- End diff --
    
    Shorten lines 616-621 to the following:
    
    ```
    return Lists.newArrayList(new StringTokenizer(gatewaySystemIds, ","));
    ```
    
    (``com.google.common.collect.Lists``)


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39903696
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,53 +226,181 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();
    +            String apiVersion = Objects.firstNonNull(cmd.getApiVersion(), (String) clientDefaults.get("CURRENT_API_VERSION"));
    +            if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
    +                throw new CloudRuntimeException("Unsupported API version : " + apiVersion);
    +            }
     
    -        try {
    +            Map<String, String> params = new HashMap<String, String>();
    +            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(Objects.firstNonNull(cmd.getApiRetryCount(), clientDefaults.get("DEFAULT_API_RETRY_COUNT"))));
    +            params.put("retryinterval", String.valueOf(Objects.firstNonNull(cmd.getApiRetryInterval(), clientDefaults.get("DEFAULT_API_RETRY_INTERVAL"))));
    +
    +            final Map<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @Override
    -                    public NuageVspDeviceVO doInTransaction(TransactionStatus status) {
    -                        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);
    -
    -                        return 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 (ConfigurationException e) {
    +        } catch (Exception e) {
    --- End diff --
    
    Why are all unchecked and checked exceptions being caught and ignored?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031285
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java ---
    @@ -48,13 +53,93 @@ public boolean isL3Network() {
             return _isL3Network;
         }
     
    +    public boolean isSharedNetwork() {
    +        return _isSharedNetwork;
    +    }
    +
         public String getVpcUuid() {
             return _vpcUuid;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<TrashNetworkVspCommand> {
    +        private String _domainUuid;
    +        private String _networkUuid;
    +        private boolean _isL3Network;
    +        private boolean _isSharedNetwork;
    +        private String _vpcUuid;
    +        private String _domainTemplateName;
    +
    +        public Builder domainUuid(String domainUuid) {
    +            this._domainUuid = domainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public TrashNetworkVspCommand build() {
    +            return new TrashNetworkVspCommand(_domainUuid, _networkUuid, _isL3Network, _isSharedNetwork, _vpcUuid, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This ``equals`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by KrisSterckx <gi...@git.apache.org>.
Github user KrisSterckx commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-147179219
  
    @remibergsma OK done now


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41804704
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -285,60 +525,345 @@ 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 (!Strings.isNullOrEmpty(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!");
    --- End diff --
    
    Why are logging to ``FATAL``?  We typically log to ``ERROR``.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39966948
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspApiClient.java ---
    @@ -23,8 +23,8 @@
     
         public void login() throws Exception;
     
    -    public void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval);
    +    public void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval, String nuageVspCmsId);
     
         public String executeRestApi(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
    -            String proxyUserDomainuuid) throws Exception;
    +                                 String proxyUserDomainuuid) throws Exception;
    --- End diff --
    
    The private client is using custom exceptions which are translated to global exceptions for use inside the CS plugin


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41804131
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        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"))) {
    +            paramsTobeUpdated.put("retryinterval", String.valueOf(command.getApiRetryInterval()));
    +        }
     
    -                        return nuageVspDevice;
    +        if (!paramsTobeUpdated.isEmpty()) {
    --- End diff --
    
    To reduce nesting, change this if to be the following:
    
    ```
    if (paramsToBeUpdated.isEmpty()) {
       return nuageVspDevice;
    }
    ```
    The rest of the method will no longer need to be nested in an ``if`` block making it much easier to read and follow.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807829
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspManagerClient.java ---
    @@ -0,0 +1,41 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package net.nuage.vsp.acs.client;
    +
    +import org.apache.commons.lang3.tuple.Pair;
    +
    +import java.util.Map;
    +
    +public interface NuageVspManagerClient {
    +
    +    Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41778678
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -454,6 +563,80 @@ protected boolean applyACLRules(Network network, List<? extends InternalIdentity
         }
     
         @Override
    +    public boolean applyNetworkACLs(Network config, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
    +        if (rules == null || rules.isEmpty()) {
    +            s_logger.debug("No rules to apply. So, delete all the existing ACL in VSP from Subnet with uuid " + config.getUuid());
    +        } else {
    +            s_logger.debug("New rules has to applied. So, delete all the existing ACL in VSP from Subnet with uuid " + config.getUuid());
    +        }
    +        if (rules != null) {
    +            s_logger.debug("Handling applyNetworkACLs for network " + config.getName() + " with " + rules.size() + " Network ACLs");
    +            applyACLRules(config, rules, true, null, rules.isEmpty());
    +        }
    +        return true;
    +    }
    +
    +    @Override
    +    public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    +        return true;
    +    }
    +
    +    @Override
    +    public boolean shutdownVpc(Vpc vpc, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
    +        if (vpc.getState().equals(Vpc.State.Inactive)) {
    +            try {
    +                Domain vpcDomain = _domainDao.findById(vpc.getDomainId());
    +                HostVO nuageVspHost = getNuageVspHost(getPhysicalNetworkId(vpc.getZoneId()));
    +                String preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key());
    +                ShutDownVpcVspCommand cmd = new ShutDownVpcVspCommand(vpcDomain.getUuid(), vpc.getUuid(), preConfiguredDomainTemplateName);
    +                ShutDownVpcVspAnswer answer = (ShutDownVpcVspAnswer) _agentMgr.easySend(nuageVspHost.getId(), cmd);
    +                if (answer == null || !answer.getResult()) {
    +                    s_logger.error("ShutDownVpcVspCommand for VPC " + vpc.getUuid() + " failed");
    +                    if ((null != answer) && (null != answer.getDetails())) {
    +                        throw new ResourceUnavailableException(answer.getDetails(), Vpc.class, vpc.getId());
    +                    }
    +                }
    +            } catch (Exception e) {
    --- End diff --
    
    What's the status of addressing this comment?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776472
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/VspResourceAnswer.java ---
    @@ -39,4 +39,22 @@ public VspResourceAnswer(VspResourceCommand cmd, Exception e) {
         public String getResourceInfo() {
             return this._resourceInfo;
         }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        VspResourceAnswer that = (VspResourceAnswer) o;
    +
    +        if (_resourceInfo != null ? !_resourceInfo.equals(that._resourceInfo) : that._resourceInfo != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return _resourceInfo != null ? _resourceInfo.hashCode() : 0;
    +    }
    --- End diff --
    
    Please implement ``toString()`` to provide debugging state information for debugging purposes.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776134
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java ---
    @@ -0,0 +1,79 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Answer;
    +
    +import java.util.Map;
    +
    +public class GetClientDefaultsAnswer extends Answer {
    +
    +    private String _currentApiVersion;
    +    private Integer _apiRetryCount;
    +    private Long _apiRetryInterval;
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Map<String, Object> defaults) {
    +        super(cmd);
    +        this._currentApiVersion = (String) defaults.get("CURRENT_API_VERSION");
    +        this._apiRetryCount = (Integer) defaults.get("DEFAULT_API_RETRY_COUNT");
    +        this._apiRetryInterval = (Long) defaults.get("DEFAULT_API_RETRY_INTERVAL");
    +    }
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Exception e) {
    +        super(cmd, e);
    +    }
    +
    +    public String getCurrentApiVersion() {
    +        return _currentApiVersion;
    +    }
    +
    +    public Integer getApiRetryCount() {
    +        return _apiRetryCount;
    +    }
    +
    +    public Long getApiRetryInterval() {
    +        return _apiRetryInterval;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        GetClientDefaultsAnswer that = (GetClientDefaultsAnswer) o;
    +
    +        if (_apiRetryCount != null ? !_apiRetryCount.equals(that._apiRetryCount) : that._apiRetryCount != null)
    +            return false;
    +        if (_apiRetryInterval != null ? !_apiRetryInterval.equals(that._apiRetryInterval) : that._apiRetryInterval != null)
    +            return false;
    +        if (_currentApiVersion != null ? !_currentApiVersion.equals(that._currentApiVersion) : that._currentApiVersion != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _currentApiVersion != null ? _currentApiVersion.hashCode() : 0;
    +        result = 31 * result + (_apiRetryCount != null ? _apiRetryCount.hashCode() : 0);
    +        result = 31 * result + (_apiRetryInterval != null ? _apiRetryInterval.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    Please implement ``toString()`` to provide debugging state information for debugging purposes.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by KrisSterckx <gi...@git.apache.org>.
Github user KrisSterckx commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-147174211
  
    Hi @remibergsma , The rebase is committed. Thanks.   
    
    (The cloudstack-pull-requests jenkins project is disabled 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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41990195
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspManagerClient.java ---
    @@ -0,0 +1,41 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package net.nuage.vsp.acs.client;
    +
    +import org.apache.commons.lang3.tuple.Pair;
    +
    +import java.util.Map;
    +
    +public interface NuageVspManagerClient {
    +
    +    Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws Exception;
    +
    +    String registerNuageVspCmsId() throws Exception;
    +
    +    boolean unregisterNuageVspCmsId(String nuageVspCmsId) throws Exception;
    --- End diff --
    
    This is how the methods are declared in our client. They need to have the same signature as defined in our client.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by remibergsma <gi...@git.apache.org>.
Github user remibergsma commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-157311229
  
    @KrisSterckx @nlivens Guys, we are ready to merge this into master/4.7 now. Since it was rebased last some weeks ago, I'll do a quick test run against current master and will then merge. Thanks all for the hard work!


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43026384
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/UpdateNuageVspDeviceCommand.java ---
    @@ -0,0 +1,61 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api;
    +
    +import com.google.common.collect.ImmutableMap;
    +
    +import java.util.Map;
    +
    +public class UpdateNuageVspDeviceCommand extends Command {
    +
    +    private final Map<String, String> _parametersToBeUpdated;
    +
    +    public UpdateNuageVspDeviceCommand(Map<String, String> parametersToBeUpdated) {
    +        super();
    +        this._parametersToBeUpdated = ImmutableMap.copyOf(parametersToBeUpdated);
    +    }
    +
    +    public Map<String, String> getParametersToBeUpdated() {
    +        return this._parametersToBeUpdated;
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This ``equals`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807732
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspGuruClient.java ---
    @@ -21,24 +21,22 @@
     
     import java.util.Collection;
     import java.util.List;
    -import java.util.Map;
     
     public interface NuageVspGuruClient {
     
    -    public void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
    -            String networkCidr, String networkGateway, String networkUuid, boolean isL3Network, String vpcName, String vpcUuid, boolean defaultEgressPolicy,
    -            Collection<String> ipAddressRange) throws Exception;
    +    void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
    +                          String networkCidr, String networkGateway, Long networkAclId, List<String> dnsServers, List<String> gatewaySystemIds, boolean isL3Network, boolean isVpc, boolean isSharedNetwork,
    +                          String networkUuid, String vpcName, String vpcUuid, boolean defaultEgressPolicy, Collection<String[]> ipAddressRange, String domainTemplateName) throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41990041
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/NuageVspPluginClientLoader.java ---
    @@ -19,28 +19,86 @@
     
     package net.nuage.vsp.acs;
     
    +import net.nuage.vsp.acs.client.NuageVspApiClient;
    +import net.nuage.vsp.acs.client.NuageVspElementClient;
    +import net.nuage.vsp.acs.client.NuageVspGuruClient;
    +import net.nuage.vsp.acs.client.NuageVspManagerClient;
    +import net.nuage.vsp.acs.client.NuageVspSyncClient;
    +
     import java.net.MalformedURLException;
     import java.net.URL;
     import java.net.URLClassLoader;
     
     public class NuageVspPluginClientLoader {
     
    -    private static NuageVspPluginClientLoader nuageVspPluginClientClassloader;
    -    private ClassLoader loader = null;
    +    private ClassLoader _loader = null;
    +
    +    private NuageVspApiClient _nuageVspApiClient;
    +    private NuageVspElementClient _nuageVspElementClient;
    +    private NuageVspGuruClient _nuageVspGuruClient;
    +    private NuageVspManagerClient _nuageVspManagerClient;
    +    private NuageVspSyncClient _nuageVspSyncClient;
    +
    +    public static final String NUAGE_PLUGIN_CLIENT_JAR_FILE = "/usr/share/nuagevsp/lib/nuage-vsp-acs-client.jar";
    +    private static final String NUAGE_VSP_API_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspApiClientImpl";
    +    private static final String NUAGE_VSP_SYNC_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspSyncClientImpl";
    +    private static final String NUAGE_VSP_ELEMENT_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspElementClientImpl";
    +    private static final String NUAGE_VSP_GURU_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspGuruClientImpl";
    +    private static final String NUAGE_VSP_MANAGER_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspManagerClientImpl";
     
         private NuageVspPluginClientLoader(String nuagePluginClientJarLocation) {
             try {
    -            loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
    +            _loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
                         getClass().getClassLoader());
             } catch (MalformedURLException e) {
    -            e.printStackTrace();
    +            throw new IllegalArgumentException(e);
             }
         }
     
    -    public static ClassLoader getClassLoader(String nuagePluginClientJarLocation) {
    -        if (nuageVspPluginClientClassloader == null) {
    -            nuageVspPluginClientClassloader = new NuageVspPluginClientLoader(nuagePluginClientJarLocation);
    -        }
    -        return nuageVspPluginClientClassloader.loader;
    +    public static NuageVspPluginClientLoader getClientLoader(String relativePath, String[] cmsUserInfo, int numRetries, int retryInterval,
    +            String nuageVspCmsId) throws Exception {
    +        NuageVspPluginClientLoader nuageVspPluginClientClassloader = new NuageVspPluginClientLoader(NUAGE_PLUGIN_CLIENT_JAR_FILE);
    +        nuageVspPluginClientClassloader.loadClasses(relativePath, cmsUserInfo, numRetries, retryInterval, nuageVspCmsId);
    +        return nuageVspPluginClientClassloader;
    +    }
    +
    +    private void loadClasses(String relativePath, String[] cmsUserInfo, int numRetries, int retryInterval, String nuageVspCmsId) throws Exception {
    --- End diff --
    
    Changed so we catch subset of checked exceptions in the method itself.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43094017
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -367,22 +483,16 @@ public boolean applyStaticNats(Network config, List<? extends StaticNat> rules)
                 sourceNatDetail.put("sourceNatVlanNetmask", sourceNatVan.getVlanNetmask());
                 sourceNatDetails.add(sourceNatDetail);
             }
    -        try {
    -            try {
    -                HostVO nuageVspHost = getNuageVspHost(config.getPhysicalNetworkId());
    -                ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(networkDomain.getUuid(), vpcOrSubnetUuid, isL3Network, sourceNatDetails);
    -                ApplyStaticNatVspAnswer answer = (ApplyStaticNatVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -                if (answer == null || !answer.getResult()) {
    -                    s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed");
    -                    if ((null != answer) && (null != answer.getDetails())) {
    -                        throw new ResourceUnavailableException(answer.getDetails(), Network.class, config.getId());
    -                    }
    -                }
    -            } catch (Exception e) {
    -                s_logger.warn("Failed to apply static Nat in Vsp " + e.getMessage());
    +
    +        HostVO nuageVspHost = getNuageVspHost(config.getPhysicalNetworkId());
    +        ApplyStaticNatVspCommand.Builder cmdBuilder = new ApplyStaticNatVspCommand.Builder().networkDomainUuid(networkDomain.getUuid())
    --- End diff --
    
    Done.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39901764
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -201,51 +234,82 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil
         @Override
         public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
                 throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    -        nic.setBroadcastUri(network.getBroadcastUri());
    -        nic.setIsolationUri(network.getBroadcastUri());
    -
    -        s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    -        DataCenter dc = _dcDao.findById(network.getDataCenterId());
    -        Account networksAccount = _accountDao.findById(network.getAccountId());
    -        DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        long networkOwnedBy = network.getAccountId();
    -        AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    -        if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
             }
     
    -        //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    -        //that we create in VSP
    -        NicVO nicFrmDB = _nicDao.findById(nic.getId());
    -        long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
    -        boolean isL3Network = isL3Network(networkOfferingId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    -        }
    -        HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -        ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(nicFrmDB.getUuid(), nic.getMacAddress(), network.getUuid(), isL3Network, vpcUuid,
    -                networksDomain.getUuid(), networksAccount.getUuid(), vm.getType().equals(VirtualMachine.Type.DomainRouter), network.getBroadcastUri().getPath().substring(1),
    -                vm.getInstanceName(), vm.getUuid(), networksDomain.getUuid(), networksAccount.getUuid());
    -        ReserveVmInterfaceVspAnswer answer = (ReserveVmInterfaceVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ReserveVmInterfaceNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +        try {
    +            nic.setBroadcastUri(network.getBroadcastUri());
    +            nic.setIsolationUri(network.getBroadcastUri());
    +
    +            s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by Pradeepgjain <gi...@git.apache.org>.
Github user Pradeepgjain commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-143280968
  
    The NuageVsp plugin functionality is extensively test automated and under daily CI at Nuage Networks. For more info, pls contact Pradeep@nuagenetworks.net (QA) 


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43025979
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/PingNuageVspCommand.java ---
    @@ -17,18 +17,37 @@
     // under the License.
     //
     
    -package com.cloud.agent.api.element;
    +package com.cloud.agent.api;
     
    -import com.cloud.agent.api.Answer;
    +import com.cloud.host.Host;
     
    -public class ShutDownVpcVspAnswer extends Answer {
    +public class PingNuageVspCommand extends PingCommand {
     
    -    public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, boolean success, String details) {
    -        super(cmd, success, details);
    +    private final boolean shouldAudit;
    +
    +    public PingNuageVspCommand(Host.Type type, long id, boolean shouldAudit) {
    +        super(type, id);
    +        this.shouldAudit = shouldAudit;
         }
     
    -    public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, Exception e) {
    -        super(cmd, e);
    +    public boolean shouldAudit() {
    +        return shouldAudit;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This equals implementation should include attributes from the ``PingCommand`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39896161
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainAnswer.java ---
    @@ -0,0 +1,37 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Answer;
    +
    +public class SyncDomainAnswer extends Answer {
    +
    +    boolean _success;
    --- End diff --
    
    Why isn't this attribute declared ``private``?  It doesn't appear to modified outside of the constructor.  Why isn't it declared ``final`` as well?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by DaanHoogland <gi...@git.apache.org>.
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41977477
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java ---
    @@ -0,0 +1,79 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Answer;
    +
    +import java.util.Map;
    +
    +public class GetClientDefaultsAnswer extends Answer {
    +
    +    private String _currentApiVersion;
    +    private Integer _apiRetryCount;
    +    private Long _apiRetryInterval;
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Map<String, Object> defaults) {
    +        super(cmd);
    +        this._currentApiVersion = (String) defaults.get("CURRENT_API_VERSION");
    +        this._apiRetryCount = (Integer) defaults.get("DEFAULT_API_RETRY_COUNT");
    +        this._apiRetryInterval = (Long) defaults.get("DEFAULT_API_RETRY_INTERVAL");
    +    }
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Exception e) {
    +        super(cmd, e);
    +    }
    +
    +    public String getCurrentApiVersion() {
    +        return _currentApiVersion;
    +    }
    +
    +    public Integer getApiRetryCount() {
    +        return _apiRetryCount;
    +    }
    +
    +    public Long getApiRetryInterval() {
    +        return _apiRetryInterval;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        GetClientDefaultsAnswer that = (GetClientDefaultsAnswer) o;
    +
    +        if (_apiRetryCount != null ? !_apiRetryCount.equals(that._apiRetryCount) : that._apiRetryCount != null)
    +            return false;
    +        if (_apiRetryInterval != null ? !_apiRetryInterval.equals(that._apiRetryInterval) : that._apiRetryInterval != null)
    +            return false;
    +        if (_currentApiVersion != null ? !_currentApiVersion.equals(that._currentApiVersion) : that._currentApiVersion != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _currentApiVersion != null ? _currentApiVersion.hashCode() : 0;
    +        result = 31 * result + (_apiRetryCount != null ? _apiRetryCount.hashCode() : 0);
    +        result = 31 * result + (_apiRetryInterval != null ? _apiRetryInterval.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    I think we can un-final it


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093455
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncNuageVspCmsIdAnswer.java ---
    @@ -0,0 +1,71 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Answer;
    +
    +public class SyncNuageVspCmsIdAnswer extends Answer {
    +
    +    private final boolean _success;
    +    private final String _nuageVspCmsId;
    +    private final SyncNuageVspCmsIdCommand.SyncType _syncType;
    +
    +    public SyncNuageVspCmsIdAnswer(boolean success, String nuageVspCmsId, SyncNuageVspCmsIdCommand.SyncType syncType) {
    +        super();
    +        this._success = success;
    +        this._nuageVspCmsId = nuageVspCmsId;
    +        this._syncType = syncType;
    +    }
    +
    +    public boolean getSuccess() {
    +        return _success;
    +    }
    +
    +    public String getNuageVspCmsId() {
    +        return _nuageVspCmsId;
    +    }
    +
    +    public SyncNuageVspCmsIdCommand.SyncType getSyncType() {
    +        return _syncType;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncNuageVspCmsIdAnswer that = (SyncNuageVspCmsIdAnswer) o;
    +
    +        if (_success != that._success) return false;
    +        if (_nuageVspCmsId != null ? !_nuageVspCmsId.equals(that._nuageVspCmsId) : that._nuageVspCmsId != null)
    +            return false;
    +        if (_syncType != that._syncType) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Answer</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43053663
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/NuageVspPluginClientLoader.java ---
    @@ -19,28 +19,101 @@
     
     package net.nuage.vsp.acs;
     
    +import net.nuage.vsp.acs.client.NuageVspApiClient;
    +import net.nuage.vsp.acs.client.NuageVspElementClient;
    +import net.nuage.vsp.acs.client.NuageVspGuruClient;
    +import net.nuage.vsp.acs.client.NuageVspManagerClient;
    +import net.nuage.vsp.acs.client.NuageVspSyncClient;
    +import org.apache.log4j.Logger;
    +
    +import javax.naming.ConfigurationException;
     import java.net.MalformedURLException;
     import java.net.URL;
     import java.net.URLClassLoader;
     
     public class NuageVspPluginClientLoader {
     
    -    private static NuageVspPluginClientLoader nuageVspPluginClientClassloader;
    -    private ClassLoader loader = null;
    +    private ClassLoader _loader = null;
    +    private static final Logger s_logger = Logger.getLogger(NuageVspPluginClientLoader.class);
    +
    +    private NuageVspApiClient _nuageVspApiClient;
    +    private NuageVspElementClient _nuageVspElementClient;
    +    private NuageVspGuruClient _nuageVspGuruClient;
    +    private NuageVspManagerClient _nuageVspManagerClient;
    +    private NuageVspSyncClient _nuageVspSyncClient;
    +
    +    private static final String NUAGE_PLUGIN_CLIENT_JAR_FILE = "/usr/share/nuagevsp/lib/nuage-vsp-acs-client.jar";
    +    private static final String NUAGE_VSP_API_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspApiClientImpl";
    +    private static final String NUAGE_VSP_SYNC_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspSyncClientImpl";
    +    private static final String NUAGE_VSP_ELEMENT_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspElementClientImpl";
    +    private static final String NUAGE_VSP_GURU_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspGuruClientImpl";
    +    private static final String NUAGE_VSP_MANAGER_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspManagerClientImpl";
     
         private NuageVspPluginClientLoader(String nuagePluginClientJarLocation) {
             try {
    -            loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
    +            _loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
                         getClass().getClassLoader());
             } catch (MalformedURLException e) {
    -            e.printStackTrace();
    +            throw new IllegalArgumentException(e);
             }
         }
     
    -    public static ClassLoader getClassLoader(String nuagePluginClientJarLocation) {
    -        if (nuageVspPluginClientClassloader == null) {
    -            nuageVspPluginClientClassloader = new NuageVspPluginClientLoader(nuagePluginClientJarLocation);
    +    public static NuageVspPluginClientLoader getClientLoader(String relativePath, String[] cmsUserInfo, int numRetries, int retryInterval,
    +            String nuageVspCmsId) throws ConfigurationException {
    +        NuageVspPluginClientLoader nuageVspPluginClientClassloader = new NuageVspPluginClientLoader(NUAGE_PLUGIN_CLIENT_JAR_FILE);
    +        nuageVspPluginClientClassloader.loadClasses(relativePath, cmsUserInfo, numRetries, retryInterval, nuageVspCmsId);
    +        return nuageVspPluginClientClassloader;
    +    }
    +
    +    private void loadClasses(String relativePath, String[] cmsUserInfo, int numRetries, int retryInterval, String nuageVspCmsId) throws ConfigurationException {
    +        try {
    +            Class<?> nuageVspApiClientClass = Class.forName(NUAGE_VSP_API_CLIENT_IMPL, true, _loader);
    +            Class<?> nuageVspSyncClientClass = Class.forName(NUAGE_VSP_SYNC_CLIENT_IMPL, true, _loader);
    +            Class<?> nuageVspGuruClientClass = Class.forName(NUAGE_VSP_GURU_CLIENT_IMPL, true, _loader);
    +            Class<?> nuageVspElementClientClass = Class.forName(NUAGE_VSP_ELEMENT_CLIENT_IMPL, true, _loader);
    +            Class<?> nuageVspManagerClientClass = Class.forName(NUAGE_VSP_MANAGER_CLIENT_IMPL, true, _loader);
    +
    +            //Instantiate the instances
    +            _nuageVspApiClient = (NuageVspApiClient)nuageVspApiClientClass.newInstance();
    +            _nuageVspApiClient.setNuageVspHost(relativePath, cmsUserInfo, numRetries, retryInterval, nuageVspCmsId);
    +            _nuageVspSyncClient = (NuageVspSyncClient)nuageVspSyncClientClass.newInstance();
    +            _nuageVspSyncClient.setNuageVspApiClient(_nuageVspApiClient);
    +            _nuageVspGuruClient = (NuageVspGuruClient)nuageVspGuruClientClass.newInstance();
    +            _nuageVspGuruClient.setNuageVspApiClient(_nuageVspApiClient);
    +            _nuageVspElementClient = (NuageVspElementClient)nuageVspElementClientClass.newInstance();
    +            _nuageVspElementClient.setNuageVspApiClient(_nuageVspApiClient);
    +            _nuageVspManagerClient = (NuageVspManagerClient)nuageVspManagerClientClass.newInstance();
    +            _nuageVspManagerClient.setNuageVspApiClient(_nuageVspApiClient);
    +        } catch (ClassNotFoundException cnfe) {
    +            s_logger.error("Error while loading classes of Nuage VSP client", cnfe);
    +            throw new ConfigurationException("Error while loading classes of Nuage VSP client");
    --- End diff --
    
    Pass ``cnfe`` into the ``ConfigurationException`` constructor to understand the cause of the 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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39896098
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/SupportedApiVersionCommand.java ---
    @@ -0,0 +1,42 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Command;
    +
    +public class SupportedApiVersionCommand extends Command {
    +
    +    String _apiVersion;
    --- End diff --
    
    What isn't this attribute declared ``final``?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41778623
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -447,13 +568,95 @@ protected boolean applyACLRules(Network network, List<? extends InternalIdentity
                 }
     
             } catch (Exception e1) {
    --- End diff --
    
    Why are all checked and unchecked exceptions being caught here?  Why not catch the subset of expected checked exceptions?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807861
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspManagerClient.java ---
    @@ -0,0 +1,41 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package net.nuage.vsp.acs.client;
    +
    +import org.apache.commons.lang3.tuple.Pair;
    +
    +import java.util.Map;
    +
    +public interface NuageVspManagerClient {
    +
    +    Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws Exception;
    +
    +    String registerNuageVspCmsId() throws Exception;
    +
    +    boolean unregisterNuageVspCmsId(String nuageVspCmsId) throws Exception;
    +
    +    boolean isSupportedApiVersion(String version);
    +
    +    Map<String, Object> getClientDefaults() throws Exception;
    +
    +    boolean syncDomainWithNuageVsp(String domainUuid, String domainName, String domainPath, boolean add, boolean remove) throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43090895
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -201,51 +234,82 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil
         @Override
         public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
                 throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    -        nic.setBroadcastUri(network.getBroadcastUri());
    -        nic.setIsolationUri(network.getBroadcastUri());
    -
    -        s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    -        DataCenter dc = _dcDao.findById(network.getDataCenterId());
    -        Account networksAccount = _accountDao.findById(network.getAccountId());
    -        DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    -        //Get the Account details and find the type
    -        long networkOwnedBy = network.getAccountId();
    -        AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    -        if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    -            throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
             }
     
    -        //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    -        //that we create in VSP
    -        NicVO nicFrmDB = _nicDao.findById(nic.getId());
    -        long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
    -        boolean isL3Network = isL3Network(networkOfferingId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    -        }
    -        HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -        ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(nicFrmDB.getUuid(), nic.getMacAddress(), network.getUuid(), isL3Network, vpcUuid,
    -                networksDomain.getUuid(), networksAccount.getUuid(), vm.getType().equals(VirtualMachine.Type.DomainRouter), network.getBroadcastUri().getPath().substring(1),
    -                vm.getInstanceName(), vm.getUuid(), networksDomain.getUuid(), networksAccount.getUuid());
    -        ReserveVmInterfaceVspAnswer answer = (ReserveVmInterfaceVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -
    -        if (answer == null || !answer.getResult()) {
    -            s_logger.error("ReserveVmInterfaceNuageVspCommand failed");
    -            if ((null != answer) && (null != answer.getDetails())) {
    -                s_logger.error(answer.getDetails());
    +        try {
    +            nic.setBroadcastUri(network.getBroadcastUri());
    +            nic.setIsolationUri(network.getBroadcastUri());
    +
    +            s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
    +            DataCenter dc = _dcDao.findById(network.getDataCenterId());
    +            Account networksAccount = _accountDao.findById(network.getAccountId());
    +            DomainVO networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            long networkOwnedBy = network.getAccountId();
    +            AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
    +            if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
    +            }
    +
    +            //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
    +            //that we create in VSP
    +            NicVO nicFrmDB = _nicDao.findById(nic.getId());
    +            NetworkOffering networkOffering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
    +            boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter);
    +            String domainRouterIp = network.getBroadcastUri().getPath().substring(1);
    --- End diff --
    
    Added your piece of code as validation, along with an additional check


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41990136
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspApiClient.java ---
    @@ -21,10 +21,10 @@
     
     public interface NuageVspApiClient {
     
    -    public void login() throws Exception;
    +    void login() throws Exception;
    --- End diff --
    
    This is how the methods are declared in our client. They need to have the same signature as defined in our client.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39895401
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/DeallocateVmVspCommand.java ---
    @@ -28,23 +28,27 @@
         String _nicMacAddress;
         String _nicIp4Address;
         boolean _isL3Network;
    +    boolean _isSharedNetwork;
         String _vpcUuid;
         String _networksDomainUuid;
         String _vmInstanceName;
         String _vmUuid;
    +    boolean _isExpungingState;
    --- End diff --
    
    Why aren't these attributes declared ``private``?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43092995
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyAclRuleVspCommand.java ---
    @@ -79,4 +191,47 @@ public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ApplyAclRuleVspCommand that = (ApplyAclRuleVspCommand) o;
    +
    +        if (_egressDefaultPolicy != that._egressDefaultPolicy) return false;
    +        if (_isL2Network != that._isL2Network) return false;
    +        if (_networkAcl != that._networkAcl) return false;
    +        if (_networkId != that._networkId) return false;
    +        if (_networkReset != that._networkReset) return false;
    +        if (_aclRules != null ? !_aclRules.equals(that._aclRules) : that._aclRules != null) return false;
    +        if (_acsIngressAcl != null ? !_acsIngressAcl.equals(that._acsIngressAcl) : that._acsIngressAcl != null)
    +            return false;
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
    +            return false;
    +        if (_networkName != null ? !_networkName.equals(that._networkName) : that._networkName != null) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-153051926
  
    @KrisSterckx I will re-review late today or early tomorrow.  Also, please bear in mind that master is current frozen.  Therefore, approval of this PR will simply pend it to be merged once the stabilization work for 4.6 is completed and master is re-opened.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807704
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspElementClient.java ---
    @@ -24,13 +24,18 @@
     
     public interface NuageVspElementClient {
     
    -    public void applyStaticNats(String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> staticNatDetails) throws Exception;
    +    boolean implement(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
    +                             boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
    +                             List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) throws Exception;
     
    -    public void applyAclRules(String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> aclRules, boolean isVpc, long networkId)
    -            throws Exception;
    +    void applyStaticNats(String networkDomainUuid, String networkUuid, String vpcOrSubnetUuid, boolean isL3Network, boolean isVpc,
    +                                List<Map<String, Object>> staticNatDetails) throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41778777
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -114,7 +117,9 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
             PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
             DataCenter dc = _dcDao.findById(plan.getDataCenterId());
             if (!canHandle(offering, dc.getNetworkType(), physnet)) {
    -            s_logger.debug("Refusing to design this network");
    +            if (s_logger.isDebugEnabled()) {
    +                s_logger.debug("Refusing to design this network");
    --- End diff --
    
    Please provide identifying/context information about the network for debugging purposes.  Also, why isn't logged as an ``ERROR``.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39906665
  
    --- 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];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            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<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (StringUtils.isNotBlank(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(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<Status, Status.Event> 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<String, Object> 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<NuageVspDeviceVO> 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<NuageVspDeviceVO> 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<Network.Service, Network.Provider> defaultNuageVspSharedSGNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
    +                    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<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
    +                    Set<Network.Provider> nuageProviders = new HashSet<Network.Provider>();
    +                    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);
    --- End diff --
    
    Could this service provider mapping be declared as a constant and initialized in a ``static`` block?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41989878
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -437,31 +463,79 @@ private Answer executeRequest(SyncVspCommand cmd) {
                 _nuageVspSyncClient.syncWithNuageVsp(cmd.getNuageVspEntity());
                 return new SyncVspAnswer(cmd, true, "Synced " + cmd.getNuageVspEntity() + " in VSP");
             } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
                 return new SyncVspAnswer(cmd, e);
             }
         }
     
    +    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
    +                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
    +                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    +            } else if (cmd.getSyncType() == SyncType.REGISTER) {
    +                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
    +                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
    +            } else {
    +                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
    +                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
    +            }
    +        } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
    --- End diff --
    
    Done.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41987775
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        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"))) {
    +            paramsTobeUpdated.put("retryinterval", String.valueOf(command.getApiRetryInterval()));
    +        }
     
    -                        return nuageVspDevice;
    +        if (!paramsTobeUpdated.isEmpty()) {
    +            Map<String, String> latestParamsValue = new HashMap<String, String>();
    +            latestParamsValue.putAll(nuageVspHost.getDetails());
    +            latestParamsValue.putAll(paramsTobeUpdated);
    +            Map<String, Object> hostdetails = new HashMap<String, Object>(latestParamsValue);
    +
    +            try {
    +                resource.configure("", hostdetails);
    +                UpdateNuageVspDeviceCommand cmd = new UpdateNuageVspDeviceCommand(latestParamsValue);
    +                UpdateNuageVspDeviceAnswer answer = (UpdateNuageVspDeviceAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +                if (answer == null || !answer.getResult()) {
    +                    s_logger.error("UpdateNuageVspDeviceCommand failed");
    +                    if ((null != answer) && (null != answer.getDetails())) {
    +                        throw new CloudRuntimeException(answer.getDetails());
                         }
    -                });
    -            } else {
    -                throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
    +                }
    +                _hostDetailsDao.persist(nuageVspDevice.getHostId(), paramsTobeUpdated);
    +            } catch (Exception e) {
    --- End diff --
    
    Changed to subset of expected checked exceptions.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41805940
  
    --- 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];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            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<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (StringUtils.isNotBlank(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(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<Status, Status.Event> 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<String, Object> 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<NuageVspDeviceVO> 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<NuageVspDeviceVO> 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) {
    --- End diff --
    
    @nlivens Any progress on addressing this comment?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093317
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java ---
    @@ -0,0 +1,79 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Answer;
    +
    +import java.util.Map;
    +
    +public class GetClientDefaultsAnswer extends Answer {
    +
    +    private String _currentApiVersion;
    +    private Integer _apiRetryCount;
    +    private Long _apiRetryInterval;
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Map<String, Object> defaults) {
    +        super(cmd);
    +        this._currentApiVersion = (String) defaults.get("CURRENT_API_VERSION");
    +        this._apiRetryCount = (Integer) defaults.get("DEFAULT_API_RETRY_COUNT");
    +        this._apiRetryInterval = (Long) defaults.get("DEFAULT_API_RETRY_INTERVAL");
    +    }
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Exception e) {
    +        super(cmd, e);
    +    }
    +
    +    public String getCurrentApiVersion() {
    +        return _currentApiVersion;
    +    }
    +
    +    public Integer getApiRetryCount() {
    +        return _apiRetryCount;
    +    }
    +
    +    public Long getApiRetryInterval() {
    +        return _apiRetryInterval;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        GetClientDefaultsAnswer that = (GetClientDefaultsAnswer) o;
    +
    +        if (_apiRetryCount != null ? !_apiRetryCount.equals(that._apiRetryCount) : that._apiRetryCount != null)
    +            return false;
    +        if (_apiRetryInterval != null ? !_apiRetryInterval.equals(that._apiRetryInterval) : that._apiRetryInterval != null)
    +            return false;
    +        if (_currentApiVersion != null ? !_currentApiVersion.equals(that._currentApiVersion) : that._currentApiVersion != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    Implemented <code>hashCode</code> method for the <code>Answer</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41806331
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -437,31 +463,79 @@ private Answer executeRequest(SyncVspCommand cmd) {
                 _nuageVspSyncClient.syncWithNuageVsp(cmd.getNuageVspEntity());
                 return new SyncVspAnswer(cmd, true, "Synced " + cmd.getNuageVspEntity() + " in VSP");
             } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
                 return new SyncVspAnswer(cmd, e);
             }
         }
     
    +    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
    +                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
    +                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    +            } else if (cmd.getSyncType() == SyncType.REGISTER) {
    +                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
    +                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
    +            } else {
    +                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
    +                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
    +            }
    +        } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
    --- End diff --
    
    Please add identifying information about Nuage VSP device to assist operational debugging.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by KrisSterckx <gi...@git.apache.org>.
Github user KrisSterckx commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-157825620
  
    Thanks @remibergsma and all reviewers  -  This is great.  This is a great add to CloudStack and a great milestone for Nuage Networks.  CloudStack + SDN  : a winning team !


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by remibergsma <gi...@git.apache.org>.
Github user remibergsma commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-147071706
  
    @nlivens @KrisSterckx I have issues building this and I also see a Jenkins build error (but the job has been removed so I cannot see if it is similar). Would you please force-push your commits so the tests will run again? Thanks!


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41777608
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncNuageVspCmsIdCommand.java ---
    @@ -0,0 +1,70 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Command;
    +
    +public class SyncNuageVspCmsIdCommand extends Command {
    +
    +    public static enum SyncType { AUDIT, AUDIT_ONLY, REGISTER, UNREGISTER }
    +
    +    private final SyncType _syncType;
    +    private final String _nuageVspCmsId;
    +
    +    public SyncNuageVspCmsIdCommand(SyncType syncType, String nuageVspCmsId) {
    +        super();
    +        this._syncType = syncType;
    +        this._nuageVspCmsId = nuageVspCmsId;
    +    }
    +
    +    public SyncType getSyncType() {
    +        return _syncType;
    +    }
    +
    +    public String getNuageVspCmsId() {
    +        return _nuageVspCmsId;
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncNuageVspCmsIdCommand that = (SyncNuageVspCmsIdCommand) o;
    +
    +        if (_nuageVspCmsId != null ? !_nuageVspCmsId.equals(that._nuageVspCmsId) : that._nuageVspCmsId != null)
    +            return false;
    +        if (_syncType != that._syncType) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _syncType != null ? _syncType.hashCode() : 0;
    +        result = 31 * result + (_nuageVspCmsId != null ? _nuageVspCmsId.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    Please implement ``toString()`` to provide debugging state information for debugging purposes.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41986564
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    +        if (nuageVspDevices == null || nuageVspDevices.size() == 0) {
    +            throw new CloudRuntimeException("Nuage VSD is not configured on physical network " + physicalNetworkId);
    +        } else {
    --- End diff --
    
    Removed the <code>else</code>.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43050959
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,50 +241,185 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @Override
    -                    public NuageVspDeviceVO doInTransaction(TransactionStatus status) {
    -                        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);
    -
    -                        return 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 (ConfigurationException e) {
    -            throw new CloudRuntimeException(e.getMessage());
    +            s_logger.error("Failed to configure Nuage VSD resource", e);
    +            throw new CloudRuntimeException("Failed to configure Nuage VSD resource", e);
    +        } catch (ExecutionException ee) {
    +            s_logger.error("Failed to add Nuage VSP device", ee);
    +            throw new CloudRuntimeException("Failed to add Nuage VSP device", ee);
    +        }
    +    }
    +
    +    @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");
    +        }
    +        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<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    +        if (nuageVspDevices == null || nuageVspDevices.isEmpty()) {
    +            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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        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);
    +        Answer 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);
    +        }
    +
    +        final int retryCount = Integer.parseInt(nuageVspHost.getDetails().get("retrycount"));
    +        if (command.getApiRetryCount() != null && command.getApiRetryCount() != retryCount) {
    +            paramsTobeUpdated.put("retrycount", String.valueOf(command.getApiRetryCount()));
    +        }
    +
    +        final int apiRetryInterval = Integer.parseInt(nuageVspHost.getDetails().get("retryinterval"));
    +        if (command.getApiRetryInterval() != null && command.getApiRetryInterval() != apiRetryInterval) {
    +            paramsTobeUpdated.put("retryinterval", String.valueOf(command.getApiRetryInterval()));
    +        }
    +
    +        if (paramsTobeUpdated.isEmpty()) {
    +            if (s_logger.isDebugEnabled()) {
    --- End diff --
    
    Collapse the ``if`` conditions on lines 395-396 into a single ``if`` statement.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39904211
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,53 +226,181 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();
    +            String apiVersion = Objects.firstNonNull(cmd.getApiVersion(), (String) clientDefaults.get("CURRENT_API_VERSION"));
    +            if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
    +                throw new CloudRuntimeException("Unsupported API version : " + apiVersion);
    +            }
     
    -        try {
    +            Map<String, String> params = new HashMap<String, String>();
    +            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(Objects.firstNonNull(cmd.getApiRetryCount(), clientDefaults.get("DEFAULT_API_RETRY_COUNT"))));
    +            params.put("retryinterval", String.valueOf(Objects.firstNonNull(cmd.getApiRetryInterval(), clientDefaults.get("DEFAULT_API_RETRY_INTERVAL"))));
    +
    +            final Map<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @Override
    -                    public NuageVspDeviceVO doInTransaction(TransactionStatus status) {
    -                        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);
    -
    -                        return 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 (ConfigurationException e) {
    +        } catch (Exception e) {
                 throw new CloudRuntimeException(e.getMessage());
             }
         }
     
         @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        if (StringUtils.isNotBlank(command.getHostName()) &&
    +                !command.getHostName().equals(nuageVspHost.getDetails().get("hostname"))) {
    +            paramsTobeUpdated.put("name", "Nuage VSD - " + command.getHostName());
    +            paramsTobeUpdated.put("hostname", command.getHostName());
    +        }
    +
    +        if (StringUtils.isNotBlank(command.getUserName()) &&
    +                !command.getUserName().equals(nuageVspHost.getDetails().get("cmsuser"))) {
    +            paramsTobeUpdated.put("cmsuser", command.getUserName());
    +        }
    +
    +        if (StringUtils.isNotBlank(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 = Objects.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);
    +        }
    +
    +        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"))) {
    +            paramsTobeUpdated.put("retryinterval", String.valueOf(command.getApiRetryInterval()));
    +        }
    +
    +        if (paramsTobeUpdated.size() > 0) {
    +            Map<String, String> latestParamsValue = new HashMap<String, String>();
    +            latestParamsValue.putAll(nuageVspHost.getDetails());
    +            latestParamsValue.putAll(paramsTobeUpdated);
    +            Map<String, Object> hostdetails = new HashMap<String, Object>();
    +            hostdetails.putAll(latestParamsValue);
    +
    +            try {
    +                resource.configure("", hostdetails);
    +                UpdateNuageVspDeviceCommand cmd = new UpdateNuageVspDeviceCommand(latestParamsValue);
    +                UpdateNuageVspDeviceAnswer answer = (UpdateNuageVspDeviceAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +                if (answer == null || !answer.getResult()) {
    +                    s_logger.error("UpdateNuageVspDeviceCommand failed");
    +                    if ((null != answer) && (null != answer.getDetails())) {
    +                        throw new CloudRuntimeException(answer.getDetails());
    +                    }
    +                }
    +                _hostDetailsDao.persist(nuageVspDevice.getHostId(), paramsTobeUpdated);
    +            } catch (Exception e) {
    --- End diff --
    
    Why are all checked and unchecked exceptions being caught and ignored here?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43091274
  
    --- Diff: plugins/network-elements/nuage-vsp/pom.xml ---
    @@ -28,6 +28,13 @@
         <version>4.6.0-SNAPSHOT</version>
         <relativePath>../../pom.xml</relativePath>
       </parent>
    +  <dependencies>
    +    <dependency>
    +      <groupId>org.apache.commons</groupId>
    +      <artifactId>commons-lang3</artifactId>
    +      <version>${cs.lang3.version}</version>
    +    </dependency>
    +  </dependencies>
    --- End diff --
    
    Because our client has no dependencies to CloudStack, we had to find a common library between the 2 which has a Pair class. Which is <code>commons-lang3</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39895422
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/ImplementNetworkVspCommand.java ---
    @@ -33,16 +34,23 @@
         String _networkName;
         String _networkCidr;
         String _networkGateway;
    +    Long _networkAclId;
    +    List<String> _dnsServers;
    +    List<String> _gatewaySystemIds;
         String _networkUuid;
         boolean _isL3Network;
    +    boolean _isVpc;
    +    boolean _isSharedNetwork;
         String _vpcName;
         String _vpcUuid;
         boolean _defaultEgressPolicy;
    -    Collection<String> _ipAddressRange;
    +    Collection<String[]> _ipAddressRange;
    +    String _domainTemplateName;
    --- End diff --
    
    Why aren't these attributes declared ``private``?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39899078
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -205,6 +250,75 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
                 return false;
             }
     
    +        final boolean egressDefaultPolicy = offering.getEgressDefaultPolicy();
    +        Domain networkDomain = _domainDao.findById(network.getDomainId());
    +        boolean isFirewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.Firewall);
    +        List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +
    +        boolean isL2Network = false, isL3Network = false, isShared = false;
    +        String subnetUuid = network.getUuid();
    +        if (offering.getGuestType() == Network.GuestType.Shared) {
    +            isShared = true;
    +            subnetUuid = networkDomain.getUuid();
    +        } else if (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.StaticNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
    +            isL3Network = true;
    +        } else {
    +            isL2Network = true;
    +        }
    +
    +        String preConfiguredDomainTemplateName = getPreConfiguredDomainTemplateName(network, offering);
    +        List<FirewallRuleVO> firewallIngressRulesToApply =
    +                _firewallRulesDao.listByNetworkPurposeTrafficType(network.getId(), FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress);
    +        for (FirewallRuleVO rule : firewallIngressRulesToApply) {
    +            // load cidrs if any
    +            rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId()));
    +        }
    +
    +        List<FirewallRuleVO> firewallEgressRulesToApply =
    +                _firewallRulesDao.listByNetworkPurposeTrafficType(network.getId(), FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress);
    +        for (FirewallRuleVO rule : firewallEgressRulesToApply) {
    +            // load cidrs if any
    +            rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId()));
    +        }
    +
    +        List<Map<String, Object>> ingressFirewallRules = Lists.transform(firewallIngressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<Map<String, Object>> egressFirewallRules = Lists.transform(firewallEgressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    --- End diff --
    
    This ``Function`` is a duplicate of the one declared on line #286.  Extract to ``private static final`` inner class to remove duplication and make the code more readable.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41973391
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainCommand.java ---
    @@ -0,0 +1,91 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Command;
    +
    +public class SyncDomainCommand extends Command {
    +
    +    private final String _domainUuid;
    +    private final String _domainName;
    +    private final String _domainPath;
    +    private final boolean _toAdd;
    +    private final boolean _toRemove;
    +
    +    public SyncDomainCommand(String domainUuid, String domainName, String domainPath, boolean toAdd, boolean toRemove) {
    +        super();
    +        this._domainUuid = domainUuid;
    +        this._domainName = domainName;
    +        this._domainPath = domainPath;
    +        this._toAdd = toAdd;
    +        this._toRemove = toRemove;
    +    }
    +
    +    public String getDomainUuid() {
    +        return _domainUuid;
    +    }
    +
    +    public String getDomainName() {
    +        return _domainName;
    +    }
    +
    +    public String getDomainPath() {
    +        return _domainPath;
    +    }
    +
    +    public boolean isToAdd() {
    +        return _toAdd;
    +    }
    +
    +    public boolean isToRemove() {
    +        return _toRemove;
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncDomainCommand that = (SyncDomainCommand) o;
    +
    +        if (_toAdd != that._toAdd) return false;
    +        if (_toRemove != that._toRemove) return false;
    +        if (_domainName != null ? !_domainName.equals(that._domainName) : that._domainName != null) return false;
    +        if (_domainPath != null ? !_domainPath.equals(that._domainPath) : that._domainPath != null) return false;
    +        if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _domainUuid != null ? _domainUuid.hashCode() : 0;
    +        result = 31 * result + (_domainName != null ? _domainName.hashCode() : 0);
    +        result = 31 * result + (_domainPath != null ? _domainPath.hashCode() : 0);
    +        result = 31 * result + (_toAdd ? 1 : 0);
    +        result = 31 * result + (_toRemove ? 1 : 0);
    +        return result;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41994256
  
    --- Diff: plugins/network-elements/nuage-vsp/pom.xml ---
    @@ -28,6 +28,13 @@
         <version>4.6.0-SNAPSHOT</version>
         <relativePath>../../pom.xml</relativePath>
       </parent>
    +  <dependencies>
    +    <dependency>
    +      <groupId>org.apache.commons</groupId>
    +      <artifactId>commons-lang3</artifactId>
    +      <version>${cs.lang3.version}</version>
    +    </dependency>
    +  </dependencies>
    --- End diff --
    
    @nlivens CloudStack already has a Pair class, ``com.cloud.utils.Pair``.  Why are we bringing another dependency for functionality that is already available?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39898949
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -395,31 +510,23 @@ public IpDeployer getIpDeployer(Network network) {
     
         @Override
         public boolean applyFWRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
    -        s_logger.debug("Handling applyFWRules for network " + network.getName() + " with " + rules.size() + " FWRules");
    -        if (rules != null && rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
    +        if (rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
                 s_logger.debug("Default ACL added by CS as system is ignored for network " + network.getName() + " with rule " + rules);
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39907080
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -441,6 +456,44 @@ private Answer executeRequest(SyncVspCommand cmd) {
             }
         }
     
    +    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
    +                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
    +                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    +            } else if (cmd.getSyncType() == SyncType.REGISTER) {
    +                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
    +                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
    +            } else {
    +                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
    +                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
    +            }
    +        } catch (Exception e) {
    +            return new SyncNuageVspCmsIdAnswer(false, null, cmd.getSyncType());
    +        }
    +    }
    +
    +    private Answer executeRequest(SyncDomainCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomainUuid(), cmd.getDomainName(), cmd.getDomainPath(), cmd.isToAdd(), cmd.isToRemove());
    +            return new SyncDomainAnswer(success);
    +        } catch (Exception e) {
    --- End diff --
    
    Log the exception to error.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43043984
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -129,66 +132,93 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
     
         @Override
         public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(network.getId(), 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
    +        }
    +
    +        NetworkVO implemented = null;
    +        try {
    +            assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    --- End diff --
    
    Personally, I love assertions.  However, as a project, we don't consistently run with assertions enabled.  Additionally, the incomplete test coverage does not guarantee that the assertion will properly exercised.  Therefore, I suggest converting into an ``if`` block and throw an ``IllegalStateException`` to ensure that the conditions is always checked.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031809
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncNuageVspCmsIdAnswer.java ---
    @@ -0,0 +1,71 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Answer;
    +
    +public class SyncNuageVspCmsIdAnswer extends Answer {
    +
    +    private final boolean _success;
    +    private final String _nuageVspCmsId;
    +    private final SyncNuageVspCmsIdCommand.SyncType _syncType;
    +
    +    public SyncNuageVspCmsIdAnswer(boolean success, String nuageVspCmsId, SyncNuageVspCmsIdCommand.SyncType syncType) {
    +        super();
    +        this._success = success;
    +        this._nuageVspCmsId = nuageVspCmsId;
    +        this._syncType = syncType;
    +    }
    +
    +    public boolean getSuccess() {
    +        return _success;
    +    }
    +
    +    public String getNuageVspCmsId() {
    +        return _nuageVspCmsId;
    +    }
    +
    +    public SyncNuageVspCmsIdCommand.SyncType getSyncType() {
    +        return _syncType;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This ``equals`` implementation should include attributes from the ``Answer`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41778039
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -205,9 +254,79 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
                 return false;
             }
     
    +        final boolean egressDefaultPolicy = offering.getEgressDefaultPolicy();
    +        Domain networkDomain = _domainDao.findById(network.getDomainId());
    +        boolean isFirewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.Firewall);
    +        List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
    +
    +        boolean isL2Network = false, isL3Network = false, isShared = false;
    +        String subnetUuid = network.getUuid();
    +        if (offering.getGuestType() == Network.GuestType.Shared) {
    +            isShared = true;
    +            subnetUuid = networkDomain.getUuid();
    +        } else if (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.StaticNat)
    +                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
    +            isL3Network = true;
    +        } else {
    +            isL2Network = true;
    +        }
    +
    +        String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
    +        List<FirewallRuleVO> firewallIngressRulesToApply = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Ingress);
    +        List<FirewallRuleVO> firewallEgressRulesToApply = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Egress);
    +
    +        List<Map<String, Object>> ingressFirewallRules = Lists.transform(firewallIngressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<Map<String, Object>> egressFirewallRules = Lists.transform(firewallEgressRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
    +            @Override
    +            public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
    +                return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
    +            }
    +        });
    +
    +        List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
    +        List<String> acsFipUuid = new ArrayList<String>();
    +        for (IPAddressVO ip : ips) {
    +            acsFipUuid.add(ip.getUuid());
    +        }
    +
    +        try {
    +            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    +            ImplementVspCommand.Builder cmdBuilder = new ImplementVspCommand.Builder().networkId(network.getId()).networkDomainUuid(networkDomain.getUuid())
    +                    .networkUuid(network.getUuid()).networkName(network.getName()).vpcOrSubnetUuid(subnetUuid).isL2Network(isL2Network).isL3Network(isL3Network)
    +                    .isVpc(false).isShared(isShared).domainTemplateName(preConfiguredDomainTemplateName).isFirewallServiceSupported(isFirewallServiceSupported)
    +                    .dnsServers(dnsServers).ingressFirewallRules(ingressFirewallRules).egressFirewallRules(egressFirewallRules).acsFipUuid(acsFipUuid)
    +                    .egressDefaultPolicy(egressDefaultPolicy);
    +            ImplementVspAnswer answer = (ImplementVspAnswer) _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
    +            if (answer == null || !answer.getResult()) {
    +                s_logger.error("ImplementVspCommand for network " + network.getUuid() + " failed");
    +                if ((null != answer) && (null != answer.getDetails())) {
    +                    throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
    +                }
    +            }
    +        } catch (Exception e) {
    --- End diff --
    
    Why are all checked and unchecked exceptions being caught here?  Why not catch the subset of expected checked exceptions?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807836
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspManagerClient.java ---
    @@ -0,0 +1,41 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package net.nuage.vsp.acs.client;
    +
    +import org.apache.commons.lang3.tuple.Pair;
    +
    +import java.util.Map;
    +
    +public interface NuageVspManagerClient {
    +
    +    Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws Exception;
    +
    +    String registerNuageVspCmsId() throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41803470
  
    --- 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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    +        if (nuageVspDevices == null || nuageVspDevices.size() == 0) {
    --- End diff --
    
    Please ``List#isEmpty()`` rather a size check as it is the idiomatic way to check that a list is empty and more clearly expresses intent.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031227
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/ReserveVmInterfaceVspCommand.java ---
    @@ -87,29 +114,285 @@ public boolean isDomainRouter() {
             return _isDomainRouter;
         }
     
    -    public String _getDomainRouterIp() {
    +    public String getDomainRouterIp() {
             return _domainRouterIp;
         }
     
    -    public String _getVmInstanceName() {
    +    public String getVmInstanceName() {
             return _vmInstanceName;
         }
     
    -    public String _getVmUuid() {
    +    public String getVmUuid() {
             return _vmUuid;
         }
     
    -    public String _getVmUserName() {
    +    public String getVmUserName() {
             return _vmUserName;
         }
     
    -    public String _getVmUserDomainName() {
    +    public String getVmUserDomainName() {
             return _vmUserDomainName;
         }
     
    +    public boolean useStaticIp() {
    +        return _useStaticIp;
    +    }
    +
    +    public String getStaticIp() {
    +        return _staticIp;
    +    }
    +
    +    public String getStaticNatIpUuid() {
    +        return _staticNatIpUuid;
    +    }
    +
    +    public String getStaticNatIpAddress() {
    +        return _staticNatIpAddress;
    +    }
    +
    +    public boolean isStaticNatIpAllocated() {
    +        return _isStaticNatIpAllocated;
    +    }
    +
    +    public boolean isOneToOneNat() {
    +        return _isOneToOneNat;
    +    }
    +
    +    public String getStaticNatVlanUuid() {
    +        return _staticNatVlanUuid;
    +    }
    +
    +    public String getStaticNatVlanGateway() {
    +        return _staticNatVlanGateway;
    +    }
    +
    +    public String getStaticNatVlanNetmask() {
    +        return _staticNatVlanNetmask;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ReserveVmInterfaceVspCommand> {
    +        private String _nicUuid;
    +        private String _nicMacAddress;
    +        private String _networkUuid;
    +        private boolean _isL3Network;
    +        private boolean _isSharedNetwork;
    +        private String _vpcUuid;
    +        private String _networkDomainUuid;
    +        private String _networksAccountUuid;
    +        private boolean _isDomainRouter;
    +        private String _domainRouterIp;
    +        private String _vmInstanceName;
    +        private String _vmUuid;
    +        private String _vmUserName;
    +        private String _vmUserDomainName;
    +        private boolean _useStaticIp;
    +        private String _staticIp;
    +        private String _staticNatIpUuid;
    +        private String _staticNatIpAddress;
    +        private boolean _isStaticNatIpAllocated;
    +        private boolean _isOneToOneNat;
    +        private String _staticNatVlanUuid;
    +        private String _staticNatVlanGateway;
    +        private String _staticNatVlanNetmask;
    +
    +        public Builder nicUuid(String nicUuid) {
    +            this._nicUuid = nicUuid;
    +            return this;
    +        }
    +
    +        public Builder nicMacAddress(String nicMacAddress) {
    +            this._nicMacAddress = nicMacAddress;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networksAccountUuid(String networksAccountUuid) {
    +            this._networksAccountUuid = networksAccountUuid;
    +            return this;
    +        }
    +
    +        public Builder isDomainRouter(boolean isDomainRouter) {
    +            this._isDomainRouter = isDomainRouter;
    +            return this;
    +        }
    +
    +        public Builder domainRouterIp(String domainRouterIp) {
    +            this._domainRouterIp = domainRouterIp;
    +            return this;
    +        }
    +
    +        public Builder vmInstanceName(String vmInstanceName) {
    +            this._vmInstanceName = vmInstanceName;
    +            return this;
    +        }
    +
    +        public Builder vmUuid(String vmUuid) {
    +            this._vmUuid = vmUuid;
    +            return this;
    +        }
    +
    +        public Builder vmUserName(String vmUserName) {
    +            this._vmUserName = vmUserName;
    +            return this;
    +        }
    +
    +        public Builder vmUserDomainName(String vmUserDomainName) {
    +            this._vmUserDomainName = vmUserDomainName;
    +            return this;
    +        }
    +
    +        public Builder useStaticIp(boolean useStaticIp) {
    +            this._useStaticIp = useStaticIp;
    +            return this;
    +        }
    +
    +        public Builder staticIp(String staticIp) {
    +            this._staticIp = staticIp;
    +            return this;
    +        }
    +
    +        public Builder staticNatIpUuid(String staticNatIpUuid) {
    +            this._staticNatIpUuid = staticNatIpUuid;
    +            return this;
    +        }
    +
    +        public Builder staticNatIpAddress(String staticNatIpAddress) {
    +            this._staticNatIpAddress = staticNatIpAddress;
    +            return this;
    +        }
    +
    +        public Builder isStaticNatIpAllocated(boolean isStaticNatIpAllocated) {
    +            this._isStaticNatIpAllocated = isStaticNatIpAllocated;
    +            return this;
    +        }
    +
    +        public Builder isOneToOneNat(boolean isOneToOneNat) {
    +            this._isOneToOneNat = isOneToOneNat;
    +            return this;
    +        }
    +
    +        public Builder staticNatVlanUuid(String staticNatVlanUuid) {
    +            this._staticNatVlanUuid = staticNatVlanUuid;
    +            return this;
    +        }
    +
    +        public Builder staticNatVlanGateway(String staticNatVlanGateway) {
    +            this._staticNatVlanGateway = staticNatVlanGateway;
    +            return this;
    +        }
    +
    +        public Builder staticNatVlanNetmask(String staticNatVlanNetmask) {
    +            this._staticNatVlanNetmask = staticNatVlanNetmask;
    +            return this;
    +        }
    +
    +        @Override
    +        public ReserveVmInterfaceVspCommand build() {
    +            return new ReserveVmInterfaceVspCommand(_nicUuid, _nicMacAddress, _networkUuid, _isL3Network, _isSharedNetwork, _vpcUuid, _networkDomainUuid, _networksAccountUuid,
    +                    _isDomainRouter, _domainRouterIp, _vmInstanceName, _vmUuid, _vmUserName, _vmUserDomainName, _useStaticIp, _staticIp, _staticNatIpUuid, _staticNatIpAddress,
    +                    _isStaticNatIpAllocated, _isOneToOneNat, _staticNatVlanUuid, _staticNatVlanGateway, _staticNatVlanNetmask);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This ``equals`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43042630
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---
    @@ -395,65 +505,135 @@ public IpDeployer getIpDeployer(Network network) {
     
         @Override
         public boolean applyFWRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
    -        s_logger.debug("Handling applyFWRules for network " + network.getName() + " with " + rules.size() + " FWRules");
    -        if (rules != null && rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
    -            s_logger.debug("Default ACL added by CS as system is ignored for network " + network.getName() + " with rule " + rules);
    +        if (rules == null || rules.isEmpty()) {
                 return true;
             }
    -        return applyACLRules(network, rules, false);
    +
    +        if (rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
    +            if (s_logger.isDebugEnabled()) {
    +                s_logger.debug("Default ACL added by CS as system is ignored for network " + network.getName() + " with rule " + rules);
    --- End diff --
    
    Should this message be a ``WARN`` severity?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43092950
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyAclRuleVspCommand.java ---
    @@ -58,20 +73,117 @@ public String getVpcOrSubnetUuid() {
             return _vpcOrSubnetUuid;
         }
     
    -    public boolean isL3Network() {
    -        return _isL3Network;
    +    public String getNetworkName() {
    +        return _networkName;
    +    }
    +
    +    public boolean isL2Network() {
    +        return _isL2Network;
         }
     
         public List<Map<String, Object>> getAclRules() {
             return _aclRules;
         }
     
    -    public boolean isVpc() {
    -        return _isVpc;
    +    public long getNetworkId() {
    +        return _networkId;
         }
     
    -    public long getNetworkId() {
    -        return this._networkId;
    +    public boolean isEgressDefaultPolicy() {
    +        return _egressDefaultPolicy;
    +    }
    +
    +    public Boolean getAcsIngressAcl() {
    +        return _acsIngressAcl;
    +    }
    +
    +    public boolean isNetworkReset() {
    +        return _networkReset;
    +    }
    +
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ApplyAclRuleVspCommand> {
    --- End diff --
    
    No, there shouldn't be any default values in my opinion.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43031307
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java ---
    @@ -48,13 +53,93 @@ public boolean isL3Network() {
             return _isL3Network;
         }
     
    +    public boolean isSharedNetwork() {
    +        return _isSharedNetwork;
    +    }
    +
         public String getVpcUuid() {
             return _vpcUuid;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<TrashNetworkVspCommand> {
    +        private String _domainUuid;
    +        private String _networkUuid;
    +        private boolean _isL3Network;
    +        private boolean _isSharedNetwork;
    +        private String _vpcUuid;
    +        private String _domainTemplateName;
    +
    +        public Builder domainUuid(String domainUuid) {
    +            this._domainUuid = domainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public TrashNetworkVspCommand build() {
    +            return new TrashNetworkVspCommand(_domainUuid, _networkUuid, _isL3Network, _isSharedNetwork, _vpcUuid, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        TrashNetworkVspCommand that = (TrashNetworkVspCommand) o;
    +
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isSharedNetwork != that._isSharedNetwork) return false;
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    This ``hashCode`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41973419
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncNuageVspCmsIdCommand.java ---
    @@ -0,0 +1,70 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Command;
    +
    +public class SyncNuageVspCmsIdCommand extends Command {
    +
    +    public static enum SyncType { AUDIT, AUDIT_ONLY, REGISTER, UNREGISTER }
    +
    +    private final SyncType _syncType;
    +    private final String _nuageVspCmsId;
    +
    +    public SyncNuageVspCmsIdCommand(SyncType syncType, String nuageVspCmsId) {
    +        super();
    +        this._syncType = syncType;
    +        this._nuageVspCmsId = nuageVspCmsId;
    +    }
    +
    +    public SyncType getSyncType() {
    +        return _syncType;
    +    }
    +
    +    public String getNuageVspCmsId() {
    +        return _nuageVspCmsId;
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncNuageVspCmsIdCommand that = (SyncNuageVspCmsIdCommand) o;
    +
    +        if (_nuageVspCmsId != null ? !_nuageVspCmsId.equals(that._nuageVspCmsId) : that._nuageVspCmsId != null)
    +            return false;
    +        if (_syncType != that._syncType) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _syncType != null ? _syncType.hashCode() : 0;
    +        result = 31 * result + (_nuageVspCmsId != null ? _nuageVspCmsId.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41777825
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDaoImpl.java ---
    @@ -36,11 +34,16 @@
             implements NuageVspDao {
     
         protected final SearchBuilder<NuageVspDeviceVO> physicalNetworkIdSearch;
    +    protected final SearchBuilder<NuageVspDeviceVO> hostIdSearch;
    --- End diff --
    
    Why are these attributes declared as ``protected`` instead of ``private``?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41985327
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -67,25 +74,76 @@
     import com.cloud.network.dao.PhysicalNetworkVO;
     import com.cloud.network.resource.NuageVspResource;
     import com.cloud.network.sync.NuageVspSync;
    +import com.cloud.network.vpc.VpcManager;
    +import com.cloud.network.vpc.VpcOffering;
    +import com.cloud.network.vpc.VpcOfferingServiceMapVO;
    +import com.cloud.network.vpc.VpcOfferingVO;
     import com.cloud.network.vpc.dao.VpcDao;
     import com.cloud.network.vpc.dao.VpcOfferingDao;
     import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao;
    +import com.cloud.network.vpc.dao.VpcServiceMapDao;
    +import com.cloud.offering.NetworkOffering;
    +import com.cloud.offerings.NetworkOfferingServiceMapVO;
    +import com.cloud.offerings.NetworkOfferingVO;
    +import com.cloud.offerings.dao.NetworkOfferingDao;
    +import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
     import com.cloud.resource.ResourceManager;
     import com.cloud.resource.ResourceState;
     import com.cloud.resource.ServerResource;
    +import com.cloud.user.AccountManager;
    +import com.cloud.user.DomainManager;
     import com.cloud.utils.component.ManagerBase;
    +import com.cloud.utils.db.DB;
     import com.cloud.utils.db.Transaction;
     import com.cloud.utils.db.TransactionCallback;
    +import com.cloud.utils.db.TransactionCallbackNoReturn;
     import com.cloud.utils.db.TransactionStatus;
     import com.cloud.utils.exception.CloudRuntimeException;
    +import com.cloud.utils.fsm.StateListener;
    +import com.cloud.utils.fsm.StateMachine2;
    +import com.google.common.base.MoreObjects;
    +import com.google.common.base.Strings;
    +import com.google.common.collect.Maps;
    +import com.google.common.collect.Sets;
    +import net.nuage.vsp.acs.NuageVspPluginClientLoader;
    +import org.apache.cloudstack.framework.config.ConfigKey;
    +import org.apache.cloudstack.framework.config.Configurable;
    +import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
    +import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
    +import org.apache.cloudstack.framework.messagebus.MessageBus;
    +import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
    +import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
    +import org.apache.commons.codec.binary.Base64;
    +import org.apache.commons.collections.CollectionUtils;
    +import org.apache.log4j.Logger;
    +
    +import javax.ejb.Local;
    +import javax.inject.Inject;
    +import javax.naming.ConfigurationException;
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.StringTokenizer;
    +import java.util.UUID;
    +import java.util.concurrent.ScheduledExecutorService;
    +
    +import static com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand.SyncType;
     
     @Local(value = {NuageVspManager.class})
    -public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager, Configurable {
    +public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager, Configurable, StateListener<Status, Status.Event, Host> {
     
         private static final Logger s_logger = Logger.getLogger(NuageVspManagerImpl.class);
     
         private static final int ONE_MINUTE_MULTIPLIER = 60 * 1000;
     
    +    private static final Set<Network.Provider> NUAGE_VSP_PROVIDERS;
    +    private static final Map<Network.Service, Set<Network.Provider>> NUAGE_VSP_VPC_SERVICE_MAP;
    +    private static final ConfigKey[] NUAGE_VSP_CONFIG_KEYS = new ConfigKey<?>[] { NuageVspConfigDns, NuageVspDnsExternal, NuageVspConfigGateway,
    --- End diff --
    
    Since this array is used as return statement
    ```java
        @Override
        public ConfigKey<?>[] getConfigKeys() {
            return NUAGE_VSP_CONFIG_KEYS;
        }
    ```
    Unless you want to create an <code>ImmutableSet</code>, and use <code>NUAGE_VSP_CONFIG_KEYS.toArray()</code> as return statement.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39902797
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +441,22 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
     
             if (allIPsInCidr.size() > 3) {
    +            //get the second IP and see if it the networks GatewayIP
                 Iterator<Long> ipIterator = allIPsInCidr.iterator();
                 long vip = ipIterator.next();
                 if (NetUtils.ip2Long(network.getGateway()) == vip) {
    -                s_logger.debug("Gateway of the Network(" + network.getUuid() + ") has the first IP " + NetUtils.long2Ip(vip));
    +                s_logger.debug("Gateway of the Network(" + network.getName() + ") has the first IP " + NetUtils.long2Ip(vip));
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776079
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainAnswer.java ---
    @@ -0,0 +1,54 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.sync;
    +
    +import com.cloud.agent.api.Answer;
    +
    +public class SyncDomainAnswer extends Answer {
    +
    +    private final boolean _success;
    +
    +    public SyncDomainAnswer(boolean success) {
    +        super();
    +        this._success = success;
    +    }
    +
    +    public boolean getSuccess() {
    +        return _success;
    +    }
    +
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SyncDomainAnswer that = (SyncDomainAnswer) o;
    +
    +        if (_success != that._success) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return (_success ? 1 : 0);
    +    }
    --- End diff --
    
    Please add a ``toString()`` method to provide debugging state information for debugging purposes.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
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<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @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 <code>Exception</code> because of <code>Map<String, Object> clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();</code>, which declares <code>throws Exception</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39906178
  
    --- 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];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            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<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (StringUtils.isNotBlank(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(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<Status, Status.Event> 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<String, Object> 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<NuageVspDeviceVO> 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<NuageVspDeviceVO> 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<Network.Service, Network.Provider> defaultNuageVspSharedSGNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
    +                    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);
    --- End diff --
    
    Wrap the call to ``s_logger.trace`` in a ``if (s_logger.isTraceEnabled()) { }`` to avoid pressure on the string pool when trace logging is disabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39902362
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -255,43 +319,22 @@ protected boolean canHandle(NetworkOffering offering, final NetworkType networkT
         }
     
         @Override
    -    public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
    -        long networkId = nic.getNetworkId();
    -        Network network = _networkDao.findById(networkId);
    -        s_logger.debug("Handling release() call back, which is called when a VM is stopped or destroyed, to delete the VM with state " + vm.getVirtualMachine().getState()
    -                + " from netork " + network.getName());
    -        if (vm.getVirtualMachine().getState().equals(VirtualMachine.State.Stopping)) {
    -            try {
    -                HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -                ReleaseVmVspCommand cmd = new ReleaseVmVspCommand(network.getUuid(), vm.getUuid(), vm.getInstanceName());
    -                ReleaseVmVspAnswer answer = (ReleaseVmVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -                if (answer == null || !answer.getResult()) {
    -                    s_logger.error("ReleaseVmNuageVspCommand for VM " + vm.getUuid() + " failed");
    -                    if ((null != answer) && (null != answer.getDetails())) {
    -                        s_logger.error(answer.getDetails());
    -                    }
    -                }
    -            } catch (InsufficientVirtualNetworkCapacityException e) {
    -                s_logger.debug("Handling release() call back. Failed to delete CS VM " + vm.getInstanceName() + " in VSP. " + e.getMessage());
    -            }
    -        } else {
    -            s_logger.debug("Handling release() call back. VM " + vm.getInstanceName() + " is in " + vm.getVirtualMachine().getState() + " state. So, the CS VM is not deleted."
    -                    + " This could be a case where VM interface is deleted. deallocate() call back should be called later");
    -        }
    -
    -        return super.release(nic, vm, reservationId);
    -    }
    -
    -    @Override
         @DB
         public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
    +        boolean lockedNetwork = lockNetworkForUserVm(network, vm);
    +        if (lockedNetwork) {
    +            s_logger.debug("Locked network " + network.getId() + " for deallocation of user VM " + vm.getInstanceName());
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41979423
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ImplementVspAnswer.java ---
    @@ -17,18 +17,27 @@
     // under the License.
     //
     
    -package com.cloud.agent.api.guru;
    +package com.cloud.agent.api.element;
     
     import com.cloud.agent.api.Answer;
    -import com.cloud.agent.api.Command;
     
    -public class ReleaseVmVspAnswer extends Answer {
    +public class ImplementVspAnswer extends Answer {
    --- End diff --
    
    Removed, using <code>Answer</code> base class instead


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41775797
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspAnswer.java ---
    @@ -31,4 +31,14 @@ public TrashNetworkVspAnswer(Command command, Exception e) {
         public TrashNetworkVspAnswer(TrashNetworkVspCommand cmd, boolean success, String details) {
             super(cmd, success, details);
         }
    +
    +    @Override
    +    public boolean equals(Object obj) {
    +        return super.equals(obj);
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return super.hashCode();
    +    }
    --- End diff --
    
    Why does this class exist?  It adds no state or behavior to the ``Answer`` base class.  Why not simply use ``Answer`` in this circumstance?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39904007
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,53 +226,181 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();
    +            String apiVersion = Objects.firstNonNull(cmd.getApiVersion(), (String) clientDefaults.get("CURRENT_API_VERSION"));
    +            if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
    +                throw new CloudRuntimeException("Unsupported API version : " + apiVersion);
    +            }
     
    -        try {
    +            Map<String, String> params = new HashMap<String, String>();
    +            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(Objects.firstNonNull(cmd.getApiRetryCount(), clientDefaults.get("DEFAULT_API_RETRY_COUNT"))));
    +            params.put("retryinterval", String.valueOf(Objects.firstNonNull(cmd.getApiRetryInterval(), clientDefaults.get("DEFAULT_API_RETRY_INTERVAL"))));
    +
    +            final Map<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @Override
    -                    public NuageVspDeviceVO doInTransaction(TransactionStatus status) {
    -                        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);
    -
    -                        return 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 (ConfigurationException e) {
    +        } catch (Exception e) {
                 throw new CloudRuntimeException(e.getMessage());
             }
         }
     
         @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        if (StringUtils.isNotBlank(command.getHostName()) &&
    +                !command.getHostName().equals(nuageVspHost.getDetails().get("hostname"))) {
    +            paramsTobeUpdated.put("name", "Nuage VSD - " + command.getHostName());
    +            paramsTobeUpdated.put("hostname", command.getHostName());
    +        }
    +
    +        if (StringUtils.isNotBlank(command.getUserName()) &&
    +                !command.getUserName().equals(nuageVspHost.getDetails().get("cmsuser"))) {
    +            paramsTobeUpdated.put("cmsuser", command.getUserName());
    +        }
    +
    +        if (StringUtils.isNotBlank(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 = Objects.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);
    +        }
    +
    +        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"))) {
    +            paramsTobeUpdated.put("retryinterval", String.valueOf(command.getApiRetryInterval()));
    +        }
    +
    +        if (paramsTobeUpdated.size() > 0) {
    --- End diff --
    
    ``List#isEmpty()`` is the preferred, idiomatic way to determine that a list is empty.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39903824
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,53 +226,181 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();
    +            String apiVersion = Objects.firstNonNull(cmd.getApiVersion(), (String) clientDefaults.get("CURRENT_API_VERSION"));
    +            if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
    +                throw new CloudRuntimeException("Unsupported API version : " + apiVersion);
    +            }
     
    -        try {
    +            Map<String, String> params = new HashMap<String, String>();
    +            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(Objects.firstNonNull(cmd.getApiRetryCount(), clientDefaults.get("DEFAULT_API_RETRY_COUNT"))));
    +            params.put("retryinterval", String.valueOf(Objects.firstNonNull(cmd.getApiRetryInterval(), clientDefaults.get("DEFAULT_API_RETRY_INTERVAL"))));
    +
    +            final Map<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @Override
    -                    public NuageVspDeviceVO doInTransaction(TransactionStatus status) {
    -                        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);
    -
    -                        return 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 (ConfigurationException e) {
    +        } catch (Exception e) {
                 throw new CloudRuntimeException(e.getMessage());
             }
         }
     
         @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<NuageVspDeviceVO> 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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        if (StringUtils.isNotBlank(command.getHostName()) &&
    +                !command.getHostName().equals(nuageVspHost.getDetails().get("hostname"))) {
    +            paramsTobeUpdated.put("name", "Nuage VSD - " + command.getHostName());
    +            paramsTobeUpdated.put("hostname", command.getHostName());
    +        }
    +
    +        if (StringUtils.isNotBlank(command.getUserName()) &&
    +                !command.getUserName().equals(nuageVspHost.getDetails().get("cmsuser"))) {
    +            paramsTobeUpdated.put("cmsuser", command.getUserName());
    +        }
    +
    +        if (StringUtils.isNotBlank(command.getPassword())) {
    --- End diff --
    
    Use Guava's implementation rather Apache Commons.  There is no need for the duplication.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39902671
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -322,35 +383,57 @@ public void shutdown(NetworkProfile profile, NetworkOffering offering) {
     
         @Override
         public boolean trash(Network network, NetworkOffering offering) {
    -
    -        s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
    -        long domainId = network.getDomainId();
    -        Domain domain = _domainDao.findById(domainId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(networkId, 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
             }
    +
             try {
    -            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -            TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(domain.getUuid(), network.getUuid(), isL3Network(offering.getId()), vpcUuid);
    -            TrashNetworkVspAnswer answer = (TrashNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -            if (answer == null || !answer.getResult()) {
    -                s_logger.error("TrashNetworkNuageVspCommand for network " + network.getUuid() + " failed");
    -                if ((null != answer) && (null != answer.getDetails())) {
    -                    s_logger.error(answer.getDetails());
    +            s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
    +            long domainId = network.getDomainId();
    +            Domain domain = _domainDao.findById(domainId);
    +            boolean isL3Network = isL3Network(network);
    +            boolean isSharedNetwork = offering.getGuestType() == GuestType.Shared;
    +            Long vpcId = network.getVpcId();
    +            String vpcUuid = null;
    +            if (vpcId != null) {
    +                Vpc vpcObj = _vpcDao.findById(vpcId);
    +                vpcUuid = vpcObj.getUuid();
    +            }
    +
    +            String preConfiguredDomainTemplateName = null;
    +            if (vpcUuid != null) {
    +                preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key());
    +            } else if (isSharedNetwork) {
    +                preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspSharedNetworkDomainTemplateName.key());
    +            } else if (isL3Network) {
    +                preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspIsolatedNetworkDomainTemplateName.key());
    +            }
    --- End diff --
    
    Extract the value passed into ``_configDao.getValue(...)`` into a local variable and call ``_configDao.getValue()`` and set the value of ``preConfiguredDomainTemplateName`` in one call -- to DRY out the implementation and make it more readable.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39902801
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -358,19 +441,22 @@ private String getVirtualRouterIP(Network network, Collection<String> addressRan
             Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
     
             if (allIPsInCidr.size() > 3) {
    +            //get the second IP and see if it the networks GatewayIP
                 Iterator<Long> ipIterator = allIPsInCidr.iterator();
                 long vip = ipIterator.next();
                 if (NetUtils.ip2Long(network.getGateway()) == vip) {
    -                s_logger.debug("Gateway of the Network(" + network.getUuid() + ") has the first IP " + NetUtils.long2Ip(vip));
    +                s_logger.debug("Gateway of the Network(" + network.getName() + ") has the first IP " + NetUtils.long2Ip(vip));
                     vip = ipIterator.next();
                     virtualRouterIp = NetUtils.long2Ip(vip);
    -                s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getUuid() + ")");
    +                s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getName() + ")");
    --- End diff --
    
    Wrap in a if (s_logger.isDebugEnabled()) { ... } block to avoid unnecessary pressure on the string pool when debug logging is not enabled.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by KrisSterckx <gi...@git.apache.org>.
Github user KrisSterckx commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-149321626
  
    @jburwell do you approve the PR ? Thanks!


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r42049470
  
    --- 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) {
    --- End diff --
    
    @nlivens what's the status of addressing this comment?


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776115
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/SupportedApiVersionCommand.java ---
    @@ -0,0 +1,58 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Command;
    +
    +public class SupportedApiVersionCommand extends Command {
    +
    +    private final String _apiVersion;
    +
    +    public SupportedApiVersionCommand(String apiVersion) {
    +        super();
    +        this._apiVersion = apiVersion;
    +    }
    +
    +    public String getApiVersion() {
    +        return _apiVersion;
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        SupportedApiVersionCommand that = (SupportedApiVersionCommand) o;
    +
    +        if (_apiVersion != null ? !_apiVersion.equals(that._apiVersion) : that._apiVersion != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        return _apiVersion != null ? _apiVersion.hashCode() : 0;
    +    }
    --- End diff --
    
    Please implement ``toString()`` to provide debugging state information for debugging purposes.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43092964
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ApplyAclRuleVspCommand.java ---
    @@ -79,4 +191,47 @@ public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    Implemented <code>equals</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41989725
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -393,9 +401,10 @@ private Answer executeRequest(DeallocateVmVspCommand cmd) {
         private Answer executeRequest(TrashNetworkVspCommand cmd) {
             try {
                 isNuageVspGuruLoaded();
    -            _nuageVspGuruClient.trash(cmd.getDomainUuid(), cmd.getNetworkUuid(), cmd.isL3Network(), cmd.getVpcUuid());
    +            _nuageVspGuruClient.trash(cmd.getDomainUuid(), cmd.getNetworkUuid(), cmd.isL3Network(), cmd.isSharedNetwork(), cmd.getVpcUuid(), cmd.getDomainTemplateName());
                 return new TrashNetworkVspAnswer(cmd, true, "Deleted Nuage VSP network mapping to " + cmd.getNetworkUuid());
             } catch (Exception e) {
    --- End diff --
    
    Our client is using internal exceptions, which are not available in ACS, and which translated to <code>Exception</code> before we return from the client. Therefore we need to catch on <code>Exception</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43103330
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -152,50 +241,185 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
                 throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
             }
     
    -        Map<String, String> params = new HashMap<String, String>();
    -        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<String, Object> hostdetails = new HashMap<String, Object>();
    -        hostdetails.putAll(params);
    +            Map<String, Object> 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<String, String> params = new HashMap<String, String>();
    +            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<String, Object> hostdetails = new HashMap<String, Object>();
    +            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<NuageVspDeviceVO>() {
    -                    @Override
    -                    public NuageVspDeviceVO doInTransaction(TransactionStatus status) {
    -                        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);
    -
    -                        return 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 (ConfigurationException e) {
    -            throw new CloudRuntimeException(e.getMessage());
    +            s_logger.error("Failed to configure Nuage VSD resource", e);
    +            throw new CloudRuntimeException("Failed to configure Nuage VSD resource", e);
    +        } catch (ExecutionException ee) {
    +            s_logger.error("Failed to add Nuage VSP device", ee);
    +            throw new CloudRuntimeException("Failed to add Nuage VSP device", ee);
    +        }
    +    }
    +
    +    @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");
    +        }
    +        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<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    +        if (nuageVspDevices == null || nuageVspDevices.isEmpty()) {
    +            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<String, String> paramsTobeUpdated = new HashMap<String, String>();
    +        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);
    +        Answer 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);
    +        }
    +
    +        final int retryCount = Integer.parseInt(nuageVspHost.getDetails().get("retrycount"));
    +        if (command.getApiRetryCount() != null && command.getApiRetryCount() != retryCount) {
    +            paramsTobeUpdated.put("retrycount", String.valueOf(command.getApiRetryCount()));
    +        }
    +
    +        final int apiRetryInterval = Integer.parseInt(nuageVspHost.getDetails().get("retryinterval"));
    +        if (command.getApiRetryInterval() != null && command.getApiRetryInterval() != apiRetryInterval) {
    +            paramsTobeUpdated.put("retryinterval", String.valueOf(command.getApiRetryInterval()));
    +        }
    +
    +        if (paramsTobeUpdated.isEmpty()) {
    +            if (s_logger.isDebugEnabled()) {
    --- End diff --
    
    There's a <code>return</code> statement right underneath the 2nd if block, we can't make the <code>return</code> statement conditional based on the logging level.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by KrisSterckx <gi...@git.apache.org>.
Github user KrisSterckx commented on the pull request:

    https://github.com/apache/cloudstack/pull/801#issuecomment-153518941
  
    Thanks @mlsorensen .
    
    We wanted to bring this plugin update in 4.6 still for the exact reason to update the community with enriched functionality with our latest released Nuage SDN platform. We kept changes to the core to the minimum for the sake of maximizing the acceptance (knowing we were pretty late in the cycle) and at the same time maximizing the benefits to the community, with added unit- & marvin test coverage. 
    
    Myself and the entire engineering who worked at this upstream contribution (dev & QA team) are still hoping for Apache CloudStack to welcome the support for the latest released Nuage VSP SDN platform and benefit the features & bug fixes it brings.



---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39904914
  
    --- 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 --
    
    What is there is nothing after the : character?  The result of the ``split`` call should be checked to ensure the length is 2.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41979565
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/UpdateNuageVspDeviceAnswer.java ---
    @@ -0,0 +1,41 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api;
    +
    +public class UpdateNuageVspDeviceAnswer extends Answer {
    --- End diff --
    
    Removed, using <code>Answer</code> base class instead


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41807645
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspApiClient.java ---
    @@ -21,10 +21,10 @@
     
     public interface NuageVspApiClient {
     
    -    public void login() throws Exception;
    +    void login() throws Exception;
     
    -    public void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval);
    +    void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval, String nuageVspCmsId);
     
    -    public String executeRestApi(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
    -            String proxyUserDomainuuid) throws Exception;
    +    String executeRestApi(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
    +                                 String proxyUserDomainuuid) throws Exception;
    --- End diff --
    
    This ``throws`` is too broad.  Please enumerate the expected checked exceptions to be thrown.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41777315
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/CmdBuilder.java ---
    @@ -0,0 +1,24 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api;
    +
    +public abstract class CmdBuilder<T> {
    --- End diff --
    
    Why is ``CmdBuilder`` an abstract class and not an interface?  Since it defines no behavior, it feels like it should be an interface.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41776261
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/DeallocateVmVspCommand.java ---
    @@ -83,9 +92,130 @@ public String getVmUuid() {
             return _vmUuid;
         }
     
    +    public boolean isExpungingState() {
    +        return _isExpungingState;
    +    }
    +
    +    public static class Builder extends CmdBuilder<DeallocateVmVspCommand> {
    +        private String _networkUuid;
    +        private String _nicFromDdUuid;
    +        private String _nicMacAddress;
    +        private String _nicIp4Address;
    +        private boolean _isL3Network;
    +        private boolean _isSharedNetwork;
    +        private String _vpcUuid;
    +        private String _networksDomainUuid;
    +        private String _vmInstanceName;
    +        private String _vmUuid;
    +        private boolean _isExpungingState;
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder nicFromDbUuid(String nicFromDbUuid) {
    +            this._nicFromDdUuid = nicFromDbUuid;
    +            return this;
    +        }
    +
    +        public Builder nicMacAddress(String nicMacAddress) {
    +            this._nicMacAddress = nicMacAddress;
    +            return this;
    +        }
    +
    +        public Builder nicIp4Address(String nicIp4Address) {
    +            this._nicIp4Address = nicIp4Address;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder networksDomainUuid(String networksDomainUuid) {
    +            this._networksDomainUuid = networksDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder vmInstanceName(String vmInstanceName) {
    +            this._vmInstanceName = vmInstanceName;
    +            return this;
    +        }
    +
    +        public Builder vmUuid(String vmUuid) {
    +            this._vmUuid = vmUuid;
    +            return this;
    +        }
    +
    +        public Builder isExpungingState(boolean isExpungingState) {
    +            this._isExpungingState = isExpungingState;
    +            return this;
    +        }
    +
    +        @Override
    +        public DeallocateVmVspCommand build() {
    +            return new DeallocateVmVspCommand(_networkUuid,_nicFromDdUuid, _nicMacAddress, _nicIp4Address, _isL3Network, _isSharedNetwork, _vpcUuid,
    +                    _networksDomainUuid, _vmInstanceName, _vmUuid, _isExpungingState);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        DeallocateVmVspCommand that = (DeallocateVmVspCommand) o;
    +
    +        if (_isExpungingState != that._isExpungingState) return false;
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isSharedNetwork != that._isSharedNetwork) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_networksDomainUuid != null ? !_networksDomainUuid.equals(that._networksDomainUuid) : that._networksDomainUuid != null)
    +            return false;
    +        if (_nicFromDdUuid != null ? !_nicFromDdUuid.equals(that._nicFromDdUuid) : that._nicFromDdUuid != null)
    +            return false;
    +        if (_nicIp4Address != null ? !_nicIp4Address.equals(that._nicIp4Address) : that._nicIp4Address != null)
    +            return false;
    +        if (_nicMacAddress != null ? !_nicMacAddress.equals(that._nicMacAddress) : that._nicMacAddress != null)
    +            return false;
    +        if (_vmInstanceName != null ? !_vmInstanceName.equals(that._vmInstanceName) : that._vmInstanceName != null)
    +            return false;
    +        if (_vmUuid != null ? !_vmUuid.equals(that._vmUuid) : that._vmUuid != null) return false;
    +        if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _networkUuid != null ? _networkUuid.hashCode() : 0;
    +        result = 31 * result + (_nicFromDdUuid != null ? _nicFromDdUuid.hashCode() : 0);
    +        result = 31 * result + (_nicMacAddress != null ? _nicMacAddress.hashCode() : 0);
    +        result = 31 * result + (_nicIp4Address != null ? _nicIp4Address.hashCode() : 0);
    +        result = 31 * result + (_isL3Network ? 1 : 0);
    +        result = 31 * result + (_isSharedNetwork ? 1 : 0);
    +        result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
    +        result = 31 * result + (_networksDomainUuid != null ? _networksDomainUuid.hashCode() : 0);
    +        result = 31 * result + (_vmInstanceName != null ? _vmInstanceName.hashCode() : 0);
    +        result = 31 * result + (_vmUuid != null ? _vmUuid.hashCode() : 0);
    +        result = 31 * result + (_isExpungingState ? 1 : 0);
    +        return result;
    +    }
    --- End diff --
    
    Please implement ``toString()`` to provide debugging state information for debugging purposes.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39902767
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -322,35 +383,57 @@ public void shutdown(NetworkProfile profile, NetworkOffering offering) {
     
         @Override
         public boolean trash(Network network, NetworkOffering offering) {
    -
    -        s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
    -        long domainId = network.getDomainId();
    -        Domain domain = _domainDao.findById(domainId);
    -        Long vpcId = network.getVpcId();
    -        String vpcUuid = null;
    -        if (vpcId != null) {
    -            Vpc vpcObj = _vpcDao.findById(vpcId);
    -            vpcUuid = vpcObj.getUuid();
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(networkId, 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
             }
    +
             try {
    -            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    -            TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(domain.getUuid(), network.getUuid(), isL3Network(offering.getId()), vpcUuid);
    -            TrashNetworkVspAnswer answer = (TrashNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    -            if (answer == null || !answer.getResult()) {
    -                s_logger.error("TrashNetworkNuageVspCommand for network " + network.getUuid() + " failed");
    -                if ((null != answer) && (null != answer.getDetails())) {
    -                    s_logger.error(answer.getDetails());
    +            s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
    +            long domainId = network.getDomainId();
    +            Domain domain = _domainDao.findById(domainId);
    +            boolean isL3Network = isL3Network(network);
    +            boolean isSharedNetwork = offering.getGuestType() == GuestType.Shared;
    +            Long vpcId = network.getVpcId();
    +            String vpcUuid = null;
    +            if (vpcId != null) {
    +                Vpc vpcObj = _vpcDao.findById(vpcId);
    +                vpcUuid = vpcObj.getUuid();
    +            }
    +
    +            String preConfiguredDomainTemplateName = null;
    +            if (vpcUuid != null) {
    +                preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key());
    +            } else if (isSharedNetwork) {
    +                preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspSharedNetworkDomainTemplateName.key());
    +            } else if (isL3Network) {
    +                preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspIsolatedNetworkDomainTemplateName.key());
    +            }
    +
    +            try {
    +                HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
    +                TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(domain.getUuid(), network.getUuid(), isL3Network, isSharedNetwork, vpcUuid, preConfiguredDomainTemplateName);
    +                TrashNetworkVspAnswer answer = (TrashNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
    +                if (answer == null || !answer.getResult()) {
    +                    s_logger.error("TrashNetworkNuageVspCommand for network " + network.getUuid() + " failed");
    +                    if ((null != answer) && (null != answer.getDetails())) {
    +                        s_logger.error(answer.getDetails());
    +                    }
                     }
    +            } catch (Exception e) {
    +                s_logger.warn("Failed to clean up network information in Vsp " + e.getMessage());
    --- End diff --
    
    Add the exception, ``e``, to the ``warn`` call to provide the stack trace in the log to assist debugging operations.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43092609
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/VspResourceCommand.java ---
    @@ -79,4 +79,41 @@ public String getProxyUserDomainuuid() {
         public boolean executeInSequence() {
             return false;
         }
    +
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    Implemented <code>equals</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39907305
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/NuageVspPluginClientLoader.java ---
    @@ -19,28 +19,86 @@
     
     package net.nuage.vsp.acs;
     
    +import net.nuage.vsp.acs.client.NuageVspApiClient;
    +import net.nuage.vsp.acs.client.NuageVspElementClient;
    +import net.nuage.vsp.acs.client.NuageVspGuruClient;
    +import net.nuage.vsp.acs.client.NuageVspManagerClient;
    +import net.nuage.vsp.acs.client.NuageVspSyncClient;
    +
     import java.net.MalformedURLException;
     import java.net.URL;
     import java.net.URLClassLoader;
     
     public class NuageVspPluginClientLoader {
     
    -    private static NuageVspPluginClientLoader nuageVspPluginClientClassloader;
    -    private ClassLoader loader = null;
    +    private ClassLoader _loader = null;
    +
    +    private NuageVspApiClient _nuageVspApiClient;
    +    private NuageVspElementClient _nuageVspElementClient;
    +    private NuageVspGuruClient _nuageVspGuruClient;
    +    private NuageVspManagerClient _nuageVspManagerClient;
    +    private NuageVspSyncClient _nuageVspSyncClient;
    +
    +    public static final String NUAGE_PLUGIN_CLIENT_JAR_FILE = "/usr/share/nuagevsp/lib/nuage-vsp-acs-client.jar";
    --- End diff --
    
    This path is not guaranteed.  Use the classpath to discover the jar.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43030931
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ImplementVspCommand.java ---
    @@ -0,0 +1,295 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.element;
    +
    +import com.cloud.agent.api.CmdBuilder;
    +import com.cloud.agent.api.Command;
    +
    +import java.util.List;
    +import java.util.Map;
    +
    +public class ImplementVspCommand extends Command {
    +
    +    private final long _networkId;
    +    private final String _networkDomainUuid;
    +    private final String _networkUuid;
    +    private final String _networkName;
    +    private final String _vpcOrSubnetUuid;
    +    private final boolean _isL2Network;
    +    private final boolean _isL3Network;
    +    private final boolean _isVpc;
    +    private final boolean _isShared;
    +    private final String _domainTemplateName;
    +    private final boolean _isFirewallServiceSupported;
    +    private final List<String> _dnsServers;
    +    private final List<Map<String, Object>> _ingressFirewallRules;
    +    private final List<Map<String, Object>> _egressFirewallRules;
    +    private final List<String> _acsFipUuid;
    +    private final boolean _egressDefaultPolicy;
    +
    +    private ImplementVspCommand(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
    +            boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
    +            List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) {
    +        super();
    +        this._networkId = networkId;
    +        this._networkDomainUuid = networkDomainUuid;
    +        this._networkUuid = networkUuid;
    +        this._networkName = networkName;
    +        this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +        this._isL2Network = isL2Network;
    +        this._isL3Network = isL3Network;
    +        this._isVpc = isVpc;
    +        this._isShared = isShared;
    +        this._domainTemplateName = domainTemplateName;
    +        this._isFirewallServiceSupported = isFirewallServiceSupported;
    +        this._dnsServers = dnsServers;
    +        this._ingressFirewallRules = ingressFirewallRules;
    +        this._egressFirewallRules = egressFirewallRules;
    +        this._acsFipUuid = acsFipUuid;
    +        this._egressDefaultPolicy = egressDefaultPolicy;
    +    }
    +
    +    public long getNetworkId() {
    +        return _networkId;
    +    }
    +
    +    public String getNetworkDomainUuid() {
    +        return _networkDomainUuid;
    +    }
    +
    +    public String getNetworkUuid() {
    +        return _networkUuid;
    +    }
    +
    +    public String getNetworkName() {
    +        return _networkName;
    +    }
    +
    +    public String getVpcOrSubnetUuid() {
    +        return _vpcOrSubnetUuid;
    +    }
    +
    +    public boolean isL2Network() {
    +        return _isL2Network;
    +    }
    +
    +    public boolean isL3Network() {
    +        return _isL3Network;
    +    }
    +
    +    public boolean isVpc() {
    +        return _isVpc;
    +    }
    +
    +    public boolean isShared() {
    +        return _isShared;
    +    }
    +
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public boolean isFirewallServiceSupported() {
    +        return _isFirewallServiceSupported;
    +    }
    +
    +    public List<String> getDnsServers() {
    +        return _dnsServers;
    +    }
    +
    +    public List<Map<String, Object>> getIngressFirewallRules() {
    +        return _ingressFirewallRules;
    +    }
    +
    +    public List<Map<String, Object>> getEgressFirewallRules() {
    +        return _egressFirewallRules;
    +    }
    +
    +    public List<String> getAcsFipUuid() {
    +        return _acsFipUuid;
    +    }
    +
    +    public boolean isEgressDefaultPolicy() {
    +        return _egressDefaultPolicy;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ImplementVspCommand> {
    +        private long _networkId;
    +        private String _networkDomainUuid;
    +        private String _networkUuid;
    +        private String _networkName;
    +        private String _vpcOrSubnetUuid;
    +        private boolean _isL2Network;
    +        private boolean _isL3Network;
    +        private boolean _isVpc;
    +        private boolean _isShared;
    +        private String _domainTemplateName;
    +        private boolean _isFirewallServiceSupported;
    +        private List<String> _dnsServers;
    +        private List<Map<String, Object>> _ingressFirewallRules;
    +        private List<Map<String, Object>> _egressFirewallRules;
    +        private List<String> _acsFipUuid;
    +        private boolean _egressDefaultPolicy;
    +
    +        public Builder networkId(long networkId) {
    +            this._networkId = networkId;
    +            return this;
    +        }
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder networkName(String networkName) {
    +            this._networkName = networkName;
    +            return this;
    +        }
    +
    +        public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
    +            this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +            return this;
    +        }
    +
    +        public Builder isL2Network(boolean isL2Network) {
    +            this._isL2Network = isL2Network;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isVpc(boolean isVpc) {
    +            this._isVpc = isVpc;
    +            return this;
    +        }
    +
    +        public Builder isShared(boolean isShared) {
    +            this._isShared = isShared;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        public Builder isFirewallServiceSupported(boolean isFirewallServiceSupported) {
    +            this._isFirewallServiceSupported = isFirewallServiceSupported;
    +            return this;
    +        }
    +
    +        public Builder dnsServers(List<String> dnsServers) {
    +            this._dnsServers = dnsServers;
    +            return this;
    +        }
    +
    +        public Builder ingressFirewallRules(List<Map<String, Object>> ingressFirewallRules) {
    +            this._ingressFirewallRules = ingressFirewallRules;
    +            return this;
    +        }
    +
    +        public Builder egressFirewallRules(List<Map<String, Object>> egressFirewallRules) {
    +            this._egressFirewallRules = egressFirewallRules;
    +            return this;
    +        }
    +
    +        public Builder acsFipUuid(List<String> acsFipUuid) {
    +            this._acsFipUuid = acsFipUuid;
    +            return this;
    +        }
    +
    +        public Builder egressDefaultPolicy(boolean egressDefaultPolicy) {
    +            this._egressDefaultPolicy = egressDefaultPolicy;
    +            return this;
    +        }
    +
    +        @Override
    +        public ImplementVspCommand build() {
    +            return new ImplementVspCommand(_networkId, _networkDomainUuid, _networkUuid, _networkName, _vpcOrSubnetUuid, _isL2Network, _isL3Network, _isVpc, _isShared,
    +                    _domainTemplateName, _isFirewallServiceSupported, _dnsServers, _ingressFirewallRules, _egressFirewallRules, _acsFipUuid, _egressDefaultPolicy);
    +        }
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    This ``equals`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41806186
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -403,20 +412,36 @@ private Answer executeRequest(TrashNetworkVspCommand cmd) {
         private Answer executeRequest(ApplyStaticNatVspCommand cmd) {
             try {
                 isNuageVspElementLoaded();
    -            _nuageVspElementClient.applyStaticNats(cmd.getNetworkDomainUuid(), cmd.getVpcOrSubnetUuid(), cmd.isL3Network(), cmd.getStaticNatDetails());
    +            _nuageVspElementClient.applyStaticNats(cmd.getNetworkDomainUuid(), cmd.getNetworkUuid(), cmd.getVpcOrSubnetUuid(), cmd.isL3Network(),
    +                    cmd.isVpc(), cmd.getStaticNatDetails());
                 return new ApplyStaticNatVspAnswer(cmd, true, "Applied Static NAT to VSP network mapping to " + cmd.getVpcOrSubnetUuid());
             } catch (Exception e) {
    +            s_logger.error("Failure during " + cmd, e);
                 return new ApplyStaticNatVspAnswer(cmd, e);
             }
         }
     
    +    private Answer executeRequest(ImplementVspCommand cmd) {
    +        try {
    +            isNuageVspElementLoaded();
    +            boolean success = _nuageVspElementClient.implement(cmd.getNetworkId(), cmd.getNetworkDomainUuid(), cmd.getNetworkUuid(), cmd.getNetworkName(), cmd.getVpcOrSubnetUuid(), cmd.isL2Network(),
    +                    cmd.isL3Network(), cmd.isVpc(), cmd.isShared(), cmd.getDomainTemplateName(), cmd.isFirewallServiceSupported(), cmd.getDnsServers(), cmd.getIngressFirewallRules(),
    +                    cmd.getEgressFirewallRules(), cmd.getAcsFipUuid(), cmd.isEgressDefaultPolicy());
    +            return new ImplementVspAnswer(cmd, success, "Implemented network in VSP " + cmd.getNetworkUuid());
    +        } catch (Exception e) {
    --- End diff --
    
    Why are all unchecked and checked exceptions being caught?  It seems like we should only be catching the expected checked exceptions, and allow unchecked exceptions simply bubble out.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39906437
  
    --- 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];
    +                }
    +            }
    +        }
    +        return null;
    +    }
     
    -        public NuageVspSyncTask(String nuageVspEntity) {
    -            this.nuageVspEntity = nuageVspEntity;
    +    public List<String> getDnsDetails(Network network) {
    +        List<String> 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<String>();
    +            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<String> getGatewaySystemIds() {
    +        List<String> gatewayIds = null;
    +        String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
    +        if (StringUtils.isNotBlank(gatewaySystemIds)) {
    +            StringTokenizer tokens = new StringTokenizer(gatewaySystemIds, ",");
    +            gatewayIds = new ArrayList<String>(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<Status, Status.Event> 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<String, Object> 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<NuageVspDeviceVO> 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<NuageVspDeviceVO> 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<Network.Service, Network.Provider> defaultNuageVspSharedSGNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
    +                    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<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
    +                    Set<Network.Provider> nuageProviders = new HashSet<Network.Provider>();
    +                    nuageProviders.add(Network.Provider.NuageVsp);
    +                    svcProviderMap.put(Network.Service.Connectivity, nuageProviders);
    --- End diff --
    
    Replace lines 789-791 with ``com.google.common.collect.Sets.newHashSet()``


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39896720
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java ---
    @@ -42,6 +28,18 @@
     import com.cloud.network.NuageVspDeviceVO;
     import com.cloud.network.manager.NuageVspManager;
     import com.cloud.utils.exception.CloudRuntimeException;
    +import org.apache.cloudstack.api.APICommand;
    +import org.apache.cloudstack.api.ApiConstants;
    +import org.apache.cloudstack.api.ApiErrorCode;
    +import org.apache.cloudstack.api.BaseListCmd;
    +import org.apache.cloudstack.api.Parameter;
    +import org.apache.cloudstack.api.ServerApiException;
    +import org.apache.cloudstack.api.response.ListResponse;
    +import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
    +
    +import javax.inject.Inject;
    +import java.util.ArrayList;
    +import java.util.List;
     
     @APICommand(name = "listNuageVspDevices", responseObject = NuageVspDeviceResponse.class, description = "Lists Nuage VSP devices")
    --- End diff --
    
    The since attribute should be declared on all APICommands for clearer documentation.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43030966
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ImplementVspCommand.java ---
    @@ -0,0 +1,295 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.element;
    +
    +import com.cloud.agent.api.CmdBuilder;
    +import com.cloud.agent.api.Command;
    +
    +import java.util.List;
    +import java.util.Map;
    +
    +public class ImplementVspCommand extends Command {
    +
    +    private final long _networkId;
    +    private final String _networkDomainUuid;
    +    private final String _networkUuid;
    +    private final String _networkName;
    +    private final String _vpcOrSubnetUuid;
    +    private final boolean _isL2Network;
    +    private final boolean _isL3Network;
    +    private final boolean _isVpc;
    +    private final boolean _isShared;
    +    private final String _domainTemplateName;
    +    private final boolean _isFirewallServiceSupported;
    +    private final List<String> _dnsServers;
    +    private final List<Map<String, Object>> _ingressFirewallRules;
    +    private final List<Map<String, Object>> _egressFirewallRules;
    +    private final List<String> _acsFipUuid;
    +    private final boolean _egressDefaultPolicy;
    +
    +    private ImplementVspCommand(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
    +            boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
    +            List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) {
    +        super();
    +        this._networkId = networkId;
    +        this._networkDomainUuid = networkDomainUuid;
    +        this._networkUuid = networkUuid;
    +        this._networkName = networkName;
    +        this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +        this._isL2Network = isL2Network;
    +        this._isL3Network = isL3Network;
    +        this._isVpc = isVpc;
    +        this._isShared = isShared;
    +        this._domainTemplateName = domainTemplateName;
    +        this._isFirewallServiceSupported = isFirewallServiceSupported;
    +        this._dnsServers = dnsServers;
    +        this._ingressFirewallRules = ingressFirewallRules;
    +        this._egressFirewallRules = egressFirewallRules;
    +        this._acsFipUuid = acsFipUuid;
    +        this._egressDefaultPolicy = egressDefaultPolicy;
    +    }
    +
    +    public long getNetworkId() {
    +        return _networkId;
    +    }
    +
    +    public String getNetworkDomainUuid() {
    +        return _networkDomainUuid;
    +    }
    +
    +    public String getNetworkUuid() {
    +        return _networkUuid;
    +    }
    +
    +    public String getNetworkName() {
    +        return _networkName;
    +    }
    +
    +    public String getVpcOrSubnetUuid() {
    +        return _vpcOrSubnetUuid;
    +    }
    +
    +    public boolean isL2Network() {
    +        return _isL2Network;
    +    }
    +
    +    public boolean isL3Network() {
    +        return _isL3Network;
    +    }
    +
    +    public boolean isVpc() {
    +        return _isVpc;
    +    }
    +
    +    public boolean isShared() {
    +        return _isShared;
    +    }
    +
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public boolean isFirewallServiceSupported() {
    +        return _isFirewallServiceSupported;
    +    }
    +
    +    public List<String> getDnsServers() {
    +        return _dnsServers;
    +    }
    +
    +    public List<Map<String, Object>> getIngressFirewallRules() {
    +        return _ingressFirewallRules;
    +    }
    +
    +    public List<Map<String, Object>> getEgressFirewallRules() {
    +        return _egressFirewallRules;
    +    }
    +
    +    public List<String> getAcsFipUuid() {
    +        return _acsFipUuid;
    +    }
    +
    +    public boolean isEgressDefaultPolicy() {
    +        return _egressDefaultPolicy;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ImplementVspCommand> {
    +        private long _networkId;
    +        private String _networkDomainUuid;
    +        private String _networkUuid;
    +        private String _networkName;
    +        private String _vpcOrSubnetUuid;
    +        private boolean _isL2Network;
    +        private boolean _isL3Network;
    +        private boolean _isVpc;
    +        private boolean _isShared;
    +        private String _domainTemplateName;
    +        private boolean _isFirewallServiceSupported;
    +        private List<String> _dnsServers;
    +        private List<Map<String, Object>> _ingressFirewallRules;
    +        private List<Map<String, Object>> _egressFirewallRules;
    +        private List<String> _acsFipUuid;
    +        private boolean _egressDefaultPolicy;
    +
    +        public Builder networkId(long networkId) {
    +            this._networkId = networkId;
    +            return this;
    +        }
    +
    +        public Builder networkDomainUuid(String networkDomainUuid) {
    +            this._networkDomainUuid = networkDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder networkName(String networkName) {
    +            this._networkName = networkName;
    +            return this;
    +        }
    +
    +        public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
    +            this._vpcOrSubnetUuid = vpcOrSubnetUuid;
    +            return this;
    +        }
    +
    +        public Builder isL2Network(boolean isL2Network) {
    +            this._isL2Network = isL2Network;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isVpc(boolean isVpc) {
    +            this._isVpc = isVpc;
    +            return this;
    +        }
    +
    +        public Builder isShared(boolean isShared) {
    +            this._isShared = isShared;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        public Builder isFirewallServiceSupported(boolean isFirewallServiceSupported) {
    +            this._isFirewallServiceSupported = isFirewallServiceSupported;
    +            return this;
    +        }
    +
    +        public Builder dnsServers(List<String> dnsServers) {
    +            this._dnsServers = dnsServers;
    +            return this;
    +        }
    +
    +        public Builder ingressFirewallRules(List<Map<String, Object>> ingressFirewallRules) {
    +            this._ingressFirewallRules = ingressFirewallRules;
    +            return this;
    +        }
    +
    +        public Builder egressFirewallRules(List<Map<String, Object>> egressFirewallRules) {
    +            this._egressFirewallRules = egressFirewallRules;
    +            return this;
    +        }
    +
    +        public Builder acsFipUuid(List<String> acsFipUuid) {
    +            this._acsFipUuid = acsFipUuid;
    +            return this;
    +        }
    +
    +        public Builder egressDefaultPolicy(boolean egressDefaultPolicy) {
    +            this._egressDefaultPolicy = egressDefaultPolicy;
    +            return this;
    +        }
    +
    +        @Override
    +        public ImplementVspCommand build() {
    +            return new ImplementVspCommand(_networkId, _networkDomainUuid, _networkUuid, _networkName, _vpcOrSubnetUuid, _isL2Network, _isL3Network, _isVpc, _isShared,
    +                    _domainTemplateName, _isFirewallServiceSupported, _dnsServers, _ingressFirewallRules, _egressFirewallRules, _acsFipUuid, _egressDefaultPolicy);
    +        }
    +    }
    +
    +    @Override
    +    public boolean executeInSequence() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        ImplementVspCommand that = (ImplementVspCommand) o;
    +
    +        if (_egressDefaultPolicy != that._egressDefaultPolicy) return false;
    +        if (_isFirewallServiceSupported != that._isFirewallServiceSupported) return false;
    +        if (_isL2Network != that._isL2Network) return false;
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isShared != that._isShared) return false;
    +        if (_isVpc != that._isVpc) return false;
    +        if (_networkId != that._networkId) return false;
    +        if (_acsFipUuid != null ? !_acsFipUuid.equals(that._acsFipUuid) : that._acsFipUuid != null) return false;
    +        if (_dnsServers != null ? !_dnsServers.equals(that._dnsServers) : that._dnsServers != null) return false;
    +        if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
    +            return false;
    +        if (_egressFirewallRules != null ? !_egressFirewallRules.equals(that._egressFirewallRules) : that._egressFirewallRules != null)
    +            return false;
    +        if (_ingressFirewallRules != null ? !_ingressFirewallRules.equals(that._ingressFirewallRules) : that._ingressFirewallRules != null)
    +            return false;
    +        if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
    +            return false;
    +        if (_networkName != null ? !_networkName.equals(that._networkName) : that._networkName != null) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    This ``hashCode`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39967011
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspElementClient.java ---
    @@ -24,12 +24,17 @@
     
     public interface NuageVspElementClient {
     
    -    public void applyStaticNats(String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> staticNatDetails) throws Exception;
    +    public boolean implement(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
    +                             boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
    +                             List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) throws Exception;
     
    -    public void applyAclRules(String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> aclRules, boolean isVpc, long networkId)
    -            throws Exception;
    +    public void applyStaticNats(String networkDomainUuid, String networkUuid, String vpcOrSubnetUuid, boolean isL3Network, boolean isVpc,
    +                                List<Map<String, Object>> staticNatDetails) throws Exception;
     
    -    public void shutDownVpc(String domainUuid, String vpcUuid) throws Exception;
    +    public void applyAclRules(boolean isNetworkAcl, String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, String networkName, boolean isL2Network,
    +                              List<Map<String, Object>> rules, long networkId, boolean egressDefaultPolicy, Boolean isAcsIngressAcl, boolean networkReset, String domainTemplateName) throws Exception;
    +
    +    public void shutdownVpc(String domainUuid, String vpcUuid, String domainTemplateName) throws Exception;
    --- End diff --
    
    The private client is using custom exceptions which are translated to global exceptions for use inside the CS plugin


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41972179
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/DeallocateVmVspCommand.java ---
    @@ -83,9 +92,130 @@ public String getVmUuid() {
             return _vmUuid;
         }
     
    +    public boolean isExpungingState() {
    +        return _isExpungingState;
    +    }
    +
    +    public static class Builder extends CmdBuilder<DeallocateVmVspCommand> {
    +        private String _networkUuid;
    +        private String _nicFromDdUuid;
    +        private String _nicMacAddress;
    +        private String _nicIp4Address;
    +        private boolean _isL3Network;
    +        private boolean _isSharedNetwork;
    +        private String _vpcUuid;
    +        private String _networksDomainUuid;
    +        private String _vmInstanceName;
    +        private String _vmUuid;
    +        private boolean _isExpungingState;
    +
    +        public Builder networkUuid(String networkUuid) {
    +            this._networkUuid = networkUuid;
    +            return this;
    +        }
    +
    +        public Builder nicFromDbUuid(String nicFromDbUuid) {
    +            this._nicFromDdUuid = nicFromDbUuid;
    +            return this;
    +        }
    +
    +        public Builder nicMacAddress(String nicMacAddress) {
    +            this._nicMacAddress = nicMacAddress;
    +            return this;
    +        }
    +
    +        public Builder nicIp4Address(String nicIp4Address) {
    +            this._nicIp4Address = nicIp4Address;
    +            return this;
    +        }
    +
    +        public Builder isL3Network(boolean isL3Network) {
    +            this._isL3Network = isL3Network;
    +            return this;
    +        }
    +
    +        public Builder isSharedNetwork(boolean isSharedNetwork) {
    +            this._isSharedNetwork = isSharedNetwork;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder networksDomainUuid(String networksDomainUuid) {
    +            this._networksDomainUuid = networksDomainUuid;
    +            return this;
    +        }
    +
    +        public Builder vmInstanceName(String vmInstanceName) {
    +            this._vmInstanceName = vmInstanceName;
    +            return this;
    +        }
    +
    +        public Builder vmUuid(String vmUuid) {
    +            this._vmUuid = vmUuid;
    +            return this;
    +        }
    +
    +        public Builder isExpungingState(boolean isExpungingState) {
    +            this._isExpungingState = isExpungingState;
    +            return this;
    +        }
    +
    +        @Override
    +        public DeallocateVmVspCommand build() {
    +            return new DeallocateVmVspCommand(_networkUuid,_nicFromDdUuid, _nicMacAddress, _nicIp4Address, _isL3Network, _isSharedNetwork, _vpcUuid,
    +                    _networksDomainUuid, _vmInstanceName, _vmUuid, _isExpungingState);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        DeallocateVmVspCommand that = (DeallocateVmVspCommand) o;
    +
    +        if (_isExpungingState != that._isExpungingState) return false;
    +        if (_isL3Network != that._isL3Network) return false;
    +        if (_isSharedNetwork != that._isSharedNetwork) return false;
    +        if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
    +        if (_networksDomainUuid != null ? !_networksDomainUuid.equals(that._networksDomainUuid) : that._networksDomainUuid != null)
    +            return false;
    +        if (_nicFromDdUuid != null ? !_nicFromDdUuid.equals(that._nicFromDdUuid) : that._nicFromDdUuid != null)
    +            return false;
    +        if (_nicIp4Address != null ? !_nicIp4Address.equals(that._nicIp4Address) : that._nicIp4Address != null)
    +            return false;
    +        if (_nicMacAddress != null ? !_nicMacAddress.equals(that._nicMacAddress) : that._nicMacAddress != null)
    +            return false;
    +        if (_vmInstanceName != null ? !_vmInstanceName.equals(that._vmInstanceName) : that._vmInstanceName != null)
    +            return false;
    +        if (_vmUuid != null ? !_vmUuid.equals(that._vmUuid) : that._vmUuid != null) return false;
    +        if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _networkUuid != null ? _networkUuid.hashCode() : 0;
    +        result = 31 * result + (_nicFromDdUuid != null ? _nicFromDdUuid.hashCode() : 0);
    +        result = 31 * result + (_nicMacAddress != null ? _nicMacAddress.hashCode() : 0);
    +        result = 31 * result + (_nicIp4Address != null ? _nicIp4Address.hashCode() : 0);
    +        result = 31 * result + (_isL3Network ? 1 : 0);
    +        result = 31 * result + (_isSharedNetwork ? 1 : 0);
    +        result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
    +        result = 31 * result + (_networksDomainUuid != null ? _networksDomainUuid.hashCode() : 0);
    +        result = 31 * result + (_vmInstanceName != null ? _vmInstanceName.hashCode() : 0);
    +        result = 31 * result + (_vmUuid != null ? _vmUuid.hashCode() : 0);
    +        result = 31 * result + (_isExpungingState ? 1 : 0);
    +        return result;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code>


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43093076
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/element/ShutDownVpcVspCommand.java ---
    @@ -40,9 +43,61 @@ public String getVpcUuid() {
             return _vpcUuid;
         }
     
    +    public String getDomainTemplateName() {
    +        return _domainTemplateName;
    +    }
    +
    +    public static class Builder implements CmdBuilder<ShutDownVpcVspCommand> {
    +        private String _domainUuid;
    +        private String _vpcUuid;
    +        private String _domainTemplateName;
    +
    +        public Builder domainUuid(String domainUuid) {
    +            this._domainUuid = domainUuid;
    +            return this;
    +        }
    +
    +        public Builder vpcUuid(String vpcUuid) {
    +            this._vpcUuid = vpcUuid;
    +            return this;
    +        }
    +
    +        public Builder domainTemplateName(String domainTemplateName) {
    +            this._domainTemplateName = domainTemplateName;
    +            return this;
    +        }
    +
    +        @Override
    +        public ShutDownVpcVspCommand build() {
    +            return new ShutDownVpcVspCommand(_domainUuid, _vpcUuid, _domainTemplateName);
    +        }
    +    }
    +
         @Override
         public boolean executeInSequence() {
             return false;
         }
     
    +    @Override
    +    public boolean equals(Object o) {
    --- End diff --
    
    Implemented <code>equals</code> method for the <code>Command</code> super class, calling it from subclass.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r39895682
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/ImplementNetworkVspCommand.java ---
    @@ -33,16 +34,23 @@
         String _networkName;
         String _networkCidr;
         String _networkGateway;
    +    Long _networkAclId;
    +    List<String> _dnsServers;
    +    List<String> _gatewaySystemIds;
         String _networkUuid;
         boolean _isL3Network;
    +    boolean _isVpc;
    +    boolean _isSharedNetwork;
         String _vpcName;
         String _vpcUuid;
         boolean _defaultEgressPolicy;
    -    Collection<String> _ipAddressRange;
    +    Collection<String[]> _ipAddressRange;
    +    String _domainTemplateName;
     
         public ImplementNetworkVspCommand(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid,
    -            String networkName, String networkCidr, String networkGateway, String networkUuid, boolean isL3Network, String vpcName, String vpcUuid, boolean defaultEgressPolicy,
    -            Collection<String> ipAddressRange) {
    +            String networkName, String networkCidr, String networkGateway, Long networkAclId, List<String> dnsServers, List<String> gatewaySystemIds, String networkUuid,
    +            boolean isL3Network, boolean isVpc, boolean isSharedNetwork, String vpcName, String vpcUuid, boolean defaultEgressPolicy, Collection<String[]> ipAddressRange,
    +            String domainTemplateName) {
    --- End diff --
    
    The number of parameters is extremely large -- creating a brittle interface and difficult to comprehend client client.  Please refactor to the Builder pattern (i.e. declare the builder a ``public static final`` inner class to create instances of ``ImplementNetworkVspCommand`` and declare the constructor of ``ImplementNetworkVspCommand`` ``private``). 


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41972064
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java ---
    @@ -0,0 +1,79 @@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +
    +package com.cloud.agent.api.manager;
    +
    +import com.cloud.agent.api.Answer;
    +
    +import java.util.Map;
    +
    +public class GetClientDefaultsAnswer extends Answer {
    +
    +    private String _currentApiVersion;
    +    private Integer _apiRetryCount;
    +    private Long _apiRetryInterval;
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Map<String, Object> defaults) {
    +        super(cmd);
    +        this._currentApiVersion = (String) defaults.get("CURRENT_API_VERSION");
    +        this._apiRetryCount = (Integer) defaults.get("DEFAULT_API_RETRY_COUNT");
    +        this._apiRetryInterval = (Long) defaults.get("DEFAULT_API_RETRY_INTERVAL");
    +    }
    +
    +    public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Exception e) {
    +        super(cmd, e);
    +    }
    +
    +    public String getCurrentApiVersion() {
    +        return _currentApiVersion;
    +    }
    +
    +    public Integer getApiRetryCount() {
    +        return _apiRetryCount;
    +    }
    +
    +    public Long getApiRetryInterval() {
    +        return _apiRetryInterval;
    +    }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        GetClientDefaultsAnswer that = (GetClientDefaultsAnswer) o;
    +
    +        if (_apiRetryCount != null ? !_apiRetryCount.equals(that._apiRetryCount) : that._apiRetryCount != null)
    +            return false;
    +        if (_apiRetryInterval != null ? !_apiRetryInterval.equals(that._apiRetryInterval) : that._apiRetryInterval != null)
    +            return false;
    +        if (_currentApiVersion != null ? !_currentApiVersion.equals(that._currentApiVersion) : that._currentApiVersion != null)
    +            return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    +        int result = _currentApiVersion != null ? _currentApiVersion.hashCode() : 0;
    +        result = 31 * result + (_apiRetryCount != null ? _apiRetryCount.hashCode() : 0);
    +        result = 31 * result + (_apiRetryInterval != null ? _apiRetryInterval.hashCode() : 0);
    +        return result;
    +    }
    --- End diff --
    
    We can't, the <code>toString()</code> method is made <code>final</code> in the base class <code>Command</code> of which <code>Answer</code> is a subclass


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41806277
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java ---
    @@ -441,6 +456,44 @@ private Answer executeRequest(SyncVspCommand cmd) {
             }
         }
     
    +    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
    +                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
    +                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
    +            } else if (cmd.getSyncType() == SyncType.REGISTER) {
    +                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
    +                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
    +            } else {
    +                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
    +                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
    +            }
    +        } catch (Exception e) {
    +            return new SyncNuageVspCmsIdAnswer(false, null, cmd.getSyncType());
    +        }
    +    }
    +
    +    private Answer executeRequest(SyncDomainCommand cmd) {
    +        try {
    +            isNuageVspManagerLoaded();
    +            boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomainUuid(), cmd.getDomainName(), cmd.getDomainPath(), cmd.isToAdd(), cmd.isToRemove());
    +            return new SyncDomainAnswer(success);
    +        } catch (Exception e) {
    --- End diff --
    
    Why are all unchecked and checked exceptions being caught?  It seems like we should only be catching the expected checked exceptions, and allow unchecked exceptions simply bubble out.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cloudstack/pull/801


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41990169
  
    --- Diff: plugins/network-elements/nuage-vsp/src/net/nuage/vsp/acs/client/NuageVspGuruClient.java ---
    @@ -21,24 +21,22 @@
     
     import java.util.Collection;
     import java.util.List;
    -import java.util.Map;
     
     public interface NuageVspGuruClient {
     
    -    public void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
    -            String networkCidr, String networkGateway, String networkUuid, boolean isL3Network, String vpcName, String vpcUuid, boolean defaultEgressPolicy,
    -            Collection<String> ipAddressRange) throws Exception;
    +    void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
    +                          String networkCidr, String networkGateway, Long networkAclId, List<String> dnsServers, List<String> gatewaySystemIds, boolean isL3Network, boolean isVpc, boolean isSharedNetwork,
    +                          String networkUuid, String vpcName, String vpcUuid, boolean defaultEgressPolicy, Collection<String[]> ipAddressRange, String domainTemplateName) throws Exception;
     
    -    public List<Map<String, String>> reserve(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, String vpcUuid, String networkDomainUuid,
    -            String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid) throws Exception;
    +    void reserve(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String networkDomainUuid,
    +                                             String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid, boolean useStaticIp, String staticIp, String staticNatIpUuid,
    +                                             String staticNatIpAddress, boolean isStaticNatIpAllocated, boolean isOneToOneNat, String staticNatVlanUuid, String staticNatVlanGateway, String staticNatVlanNetmask) throws Exception;
     
    -    public void release(String networkUuid, String vmUuid, String vmInstanceName) throws Exception;
    +    void deallocate(String networkUuid, String nicFrmDdUuid, String nicMacAddress, String nicIp4Address, boolean isL3Network, boolean isSharedNetwork,
    +                           String vpcUuid, String networksDomainUuid, String vmInstanceName, String vmUuid, boolean isExpungingState) throws Exception;
    --- End diff --
    
    This is how the methods are declared in our client. They need to have the same signature as defined in our client.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by jburwell <gi...@git.apache.org>.
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43026868
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/VspResourceCommand.java ---
    @@ -79,4 +79,41 @@ public String getProxyUserDomainuuid() {
         public boolean executeInSequence() {
             return false;
         }
    +
    +    @Override
    +    public boolean equals(Object o) {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +
    +        VspResourceCommand that = (VspResourceCommand) o;
    +
    +        if (_childResource != null ? !_childResource.equals(that._childResource) : that._childResource != null)
    +            return false;
    +        if (_entityDetails != null ? !_entityDetails.equals(that._entityDetails) : that._entityDetails != null)
    +            return false;
    +        if (_method != null ? !_method.equals(that._method) : that._method != null) return false;
    +        if (_proxyUserDomainuuid != null ? !_proxyUserDomainuuid.equals(that._proxyUserDomainuuid) : that._proxyUserDomainuuid != null)
    +            return false;
    +        if (_proxyUserUuid != null ? !_proxyUserUuid.equals(that._proxyUserUuid) : that._proxyUserUuid != null)
    +            return false;
    +        if (_resource != null ? !_resource.equals(that._resource) : that._resource != null) return false;
    +        if (_resourceFilter != null ? !_resourceFilter.equals(that._resourceFilter) : that._resourceFilter != null)
    +            return false;
    +        if (_resourceId != null ? !_resourceId.equals(that._resourceId) : that._resourceId != null) return false;
    +
    +        return true;
    +    }
    +
    +    @Override
    +    public int hashCode() {
    --- End diff --
    
    This ``hashCode`` implementation should include attributes from the ``Command`` super class.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43103443
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java ---
    @@ -285,60 +529,334 @@ 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 (!Strings.isNullOrEmpty(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.error("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)) {
    --- End diff --
    
    Done.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r43095672
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -409,8 +472,8 @@ private HostVO getNuageVspHost(long physicalNetworkId) throws InsufficientVirtua
                 nuageVspHost = _hostDao.findById(config.getHostId());
                 _hostDao.loadDetails(nuageVspHost);
             } else {
    -            throw new InsufficientVirtualNetworkCapacityException("Nuage VSD is not configured on physical network ", PhysicalNetwork.class, physicalNetworkId);
    +            throw new CloudRuntimeException("Nuage VSD is not configured on physical network " + physicalNetworkId);
    --- End diff --
    
    Changed code to <code>throw new CloudRuntimeException("There is no Nuage VSP device configured on physical network " + physicalNetworkId)</code>. We can't identify about the Nuage VSP device that failed since there is none configured.


---
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.
---

[GitHub] cloudstack pull request: CLOUDSTACK-8832 : Update Nuage VSP plugin...

Posted by nlivens <gi...@git.apache.org>.
Github user nlivens commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/801#discussion_r41981328
  
    --- Diff: plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java ---
    @@ -129,66 +134,94 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
     
         @Override
         public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    +        long networkId = network.getId();
    +        network = _networkDao.acquireInLockTable(network.getId(), 1200);
    +        if (network == null) {
    +            throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
    +        }
     
    -        assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +        NetworkVO implemented = null;
    +        try {
    +            assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    +
    +            long dcId = dest.getDataCenter().getId();
    +            //Get physical network id
    +            Long physicalNetworkId = network.getPhysicalNetworkId();
    +            //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
    +            if (physicalNetworkId == null) {
    +                physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    +            }
    +            implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
    +                    network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    +            if (network.getGateway() != null) {
    +                implemented.setGateway(network.getGateway());
    +            }
    +            if (network.getCidr() != null) {
    +                implemented.setCidr(network.getCidr());
    +            }
    +            List<String[]> ipAddressRanges = new ArrayList<String[]>();
    +            String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
    +            String networkUuid = implemented.getUuid();
    +            String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
    +            String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
    +            implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
    +            implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
    +            //Check if the network is associated to a VPC
    +            Long vpcId = network.getVpcId();
    +            boolean isVpc = (vpcId != null);
    +            //Check owner of the Network
    +            Domain networksDomain = _domainDao.findById(network.getDomainId());
    +            //Get the Account details and find the type
    +            AccountVO networksAccount = _accountDao.findById(network.getAccountId());
    +            if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    +                String errorMessage = "CS project support is not yet implemented in NuageVsp";
    +                if (s_logger.isDebugEnabled()) {
    --- End diff --
    
    Changed log level to <code>ERROR</code>.


---
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.
---