http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java index 4a01fdc..b3f8f8e 100644 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/TrashNetworkVspCommand.java @@ -19,94 +19,20 @@ package com.cloud.agent.api.guru; -import com.cloud.agent.api.CmdBuilder; import com.cloud.agent.api.Command; +import net.nuage.vsp.acs.client.api.model.VspNetwork; public class TrashNetworkVspCommand extends Command { - private final String _domainUuid; - private final String _networkUuid; - private final boolean _isL3Network; - private final boolean _isSharedNetwork; - private final String _vpcUuid; - private final String _domainTemplateName; + private final VspNetwork _network; - private TrashNetworkVspCommand(String domainUuid, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String domainTemplateName) { + public TrashNetworkVspCommand(VspNetwork network) { super(); - this._domainUuid = domainUuid; - this._networkUuid = networkUuid; - this._isL3Network = isL3Network; - this._isSharedNetwork = isSharedNetwork; - this._vpcUuid = vpcUuid; - this._domainTemplateName = domainTemplateName; + this._network = network; } - public String getDomainUuid() { - return _domainUuid; - } - - public String getNetworkUuid() { - return _networkUuid; - } - - 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); - } + public VspNetwork getNetwork() { + return _network; } @Override @@ -122,13 +48,7 @@ public class TrashNetworkVspCommand extends Command { 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; + if (_network != null ? !_network.equals(that._network) : that._network != null) return false; return true; } @@ -136,12 +56,7 @@ public class TrashNetworkVspCommand extends Command { @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + (_domainUuid != null ? _domainUuid.hashCode() : 0); - result = 31 * result + (_networkUuid != null ? _networkUuid.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 + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0); + result = 31 * result + (_network != null ? _network.hashCode() : 0); return result; } }
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetApiDefaultsAnswer.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetApiDefaultsAnswer.java b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetApiDefaultsAnswer.java new file mode 100644 index 0000000..c02eef1 --- /dev/null +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetApiDefaultsAnswer.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.manager; + +import com.cloud.agent.api.Answer; +import net.nuage.vsp.acs.client.api.model.VspApiDefaults; + +public class GetApiDefaultsAnswer extends Answer { + + private VspApiDefaults _apiDefaults; + + public GetApiDefaultsAnswer(GetApiDefaultsCommand cmd, VspApiDefaults defaults) { + super(cmd); + this._apiDefaults = defaults; + } + + public GetApiDefaultsAnswer(GetApiDefaultsCommand cmd, Exception e) { + super(cmd, e); + } + + public VspApiDefaults getApiDefaults() { + return _apiDefaults; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof GetApiDefaultsAnswer)) return false; + if (!super.equals(o)) return false; + + GetApiDefaultsAnswer that = (GetApiDefaultsAnswer) o; + + if (_apiDefaults != null ? !_apiDefaults.equals(that._apiDefaults) : that._apiDefaults != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (_apiDefaults != null ? _apiDefaults.hashCode() : 0); + return result; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetApiDefaultsCommand.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetApiDefaultsCommand.java b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetApiDefaultsCommand.java new file mode 100644 index 0000000..3fca16a --- /dev/null +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetApiDefaultsCommand.java @@ -0,0 +1,38 @@ +// +// 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; + +/** + * The super class implementations for equals and hashCode are acceptable because this class does not track any state + * in addition to the super class. + */ +public class GetApiDefaultsCommand extends Command { + + public GetApiDefaultsCommand() { + super(); + } + + @Override + public boolean executeInSequence() { + return false; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java deleted file mode 100644 index f748e1c..0000000 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsAnswer.java +++ /dev/null @@ -1,81 +0,0 @@ -// -// 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 instanceof GetClientDefaultsAnswer)) return false; - if (!super.equals(o)) 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 = super.hashCode(); - result = 31 * result + (_currentApiVersion != null ? _currentApiVersion.hashCode() : 0); - result = 31 * result + (_apiRetryCount != null ? _apiRetryCount.hashCode() : 0); - result = 31 * result + (_apiRetryInterval != null ? _apiRetryInterval.hashCode() : 0); - return result; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsCommand.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsCommand.java b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsCommand.java deleted file mode 100644 index 2ffbe04..0000000 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/manager/GetClientDefaultsCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -// -// 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; - -/** - * The super class implementations for equals and hashCode are acceptable because this class does not track any state - * in addition to the super class. - */ -public class GetClientDefaultsCommand extends Command { - - public GetClientDefaultsCommand() { - super(); - } - - @Override - public boolean executeInSequence() { - return false; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainCommand.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainCommand.java b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainCommand.java index 7ae474f..90a30a4 100644 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainCommand.java +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncDomainCommand.java @@ -20,34 +20,23 @@ package com.cloud.agent.api.sync; import com.cloud.agent.api.Command; +import net.nuage.vsp.acs.client.api.model.VspDomain; public class SyncDomainCommand extends Command { - private final String _domainUuid; - private final String _domainName; - private final String _domainPath; + private final VspDomain _domain; private final boolean _toAdd; private final boolean _toRemove; - public SyncDomainCommand(String domainUuid, String domainName, String domainPath, boolean toAdd, boolean toRemove) { + public SyncDomainCommand(VspDomain domain, boolean toAdd, boolean toRemove) { super(); - this._domainUuid = domainUuid; - this._domainName = domainName; - this._domainPath = domainPath; + this._domain = domain; this._toAdd = toAdd; this._toRemove = toRemove; } - public String getDomainUuid() { - return _domainUuid; - } - - public String getDomainName() { - return _domainName; - } - - public String getDomainPath() { - return _domainPath; + public VspDomain getDomain() { + return _domain; } public boolean isToAdd() { @@ -73,9 +62,7 @@ public class SyncDomainCommand extends Command { 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; + if (_domain != null ? !_domain.equals(that._domain) : that._domain != null) return false; return true; } @@ -83,9 +70,7 @@ public class SyncDomainCommand extends Command { @Override public int hashCode() { int result = super.hashCode(); - result = 31 * 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 + (_domain != null ? _domain.hashCode() : 0); result = 31 * result + (_toAdd ? 1 : 0); result = 31 * result + (_toRemove ? 1 : 0); return result; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncVspCommand.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncVspCommand.java b/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncVspCommand.java deleted file mode 100644 index cfcfb87..0000000 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/sync/SyncVspCommand.java +++ /dev/null @@ -1,62 +0,0 @@ -// -// 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 SyncVspCommand extends Command { - - private final String _nuageVspEntity; - - public SyncVspCommand(String nuageVspEntity) { - super(); - this._nuageVspEntity = nuageVspEntity; - } - - @Override - public boolean executeInSequence() { - return false; - } - - public String getNuageVspEntity() { - return _nuageVspEntity; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SyncVspCommand)) return false; - if (!super.equals(o)) return false; - - SyncVspCommand that = (SyncVspCommand) o; - - if (_nuageVspEntity != null ? !_nuageVspEntity.equals(that._nuageVspEntity) : that._nuageVspEntity != null) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (_nuageVspEntity != null ? _nuageVspEntity.hashCode() : 0); - return result; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/AddNuageVspDeviceCmd.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/AddNuageVspDeviceCmd.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/AddNuageVspDeviceCmd.java index 7590901..62a15ea 100644 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/AddNuageVspDeviceCmd.java +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/AddNuageVspDeviceCmd.java @@ -29,6 +29,7 @@ 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.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -41,9 +42,12 @@ import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; -@APICommand(name = "addNuageVspDevice", responseObject = NuageVspDeviceResponse.class, description = "Adds a Nuage VSP device", since = "4.5") +@APICommand(name = AddNuageVspDeviceCmd.APINAME, description = "Adds a Nuage VSP device", responseObject = NuageVspDeviceResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + since = "4.5", + authorized = {RoleType.Admin}) public class AddNuageVspDeviceCmd extends BaseAsyncCmd { - private static final String s_name = "addnuagevspdeviceresponse"; + public static final String APINAME = "addNuageVspDevice"; @Inject NuageVspManager _nuageVspManager; @@ -68,14 +72,14 @@ public class AddNuageVspDeviceCmd extends BaseAsyncCmd { @Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "the password of CMS user in Nuage VSD") private String password; - @Parameter(name = VspConstants.NUAGE_VSP_API_VERSION, type = CommandType.STRING, required = true, description = "the version of the API to use to communicate to Nuage VSD") + @Parameter(name = VspConstants.NUAGE_VSP_API_VERSION, type = CommandType.STRING, description = "the version of the API to use to communicate to Nuage VSD") private String apiVersion; - @Parameter(name = VspConstants.NUAGE_VSP_API_RETRY_COUNT, type = CommandType.INTEGER, required = true, description = "the number of retries on failure to communicate to Nuage VSD") - private int apiRetryCount; + @Parameter(name = VspConstants.NUAGE_VSP_API_RETRY_COUNT, type = CommandType.INTEGER, description = "the number of retries on failure to communicate to Nuage VSD") + private Integer apiRetryCount; - @Parameter(name = VspConstants.NUAGE_VSP_API_RETRY_INTERVAL, type = CommandType.LONG, required = true, description = "the time to wait after failure before retrying to communicate to Nuage VSD") - private long apiRetryInterval; + @Parameter(name = VspConstants.NUAGE_VSP_API_RETRY_INTERVAL, type = CommandType.LONG, description = "the time to wait after failure before retrying to communicate to Nuage VSD") + private Long apiRetryInterval; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -117,7 +121,7 @@ public class AddNuageVspDeviceCmd extends BaseAsyncCmd { this.apiVersion = apiVersion; } - public int getApiRetryCount() { + public Integer getApiRetryCount() { return apiRetryCount; } @@ -125,7 +129,7 @@ public class AddNuageVspDeviceCmd extends BaseAsyncCmd { this.apiRetryCount = apiRetryCount; } - public long getApiRetryInterval() { + public Long getApiRetryInterval() { return apiRetryInterval; } @@ -158,7 +162,7 @@ public class AddNuageVspDeviceCmd extends BaseAsyncCmd { @Override public String getCommandName() { - return s_name; + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; } @Override http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java index 971f9c9..05a17d6 100644 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java @@ -28,9 +28,11 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.manager.NuageVspManager; import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; 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.SuccessResponse; @@ -38,9 +40,13 @@ import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; -@APICommand(name = "deleteNuageVspDevice", responseObject = SuccessResponse.class, description = "delete a nuage vsp device", since = "4.5") +@APICommand(name = DeleteNuageVspDeviceCmd.APINAME, description = "delete a nuage vsp device", responseObject = SuccessResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + since = "4.5", + authorized = {RoleType.Admin}) public class DeleteNuageVspDeviceCmd extends BaseAsyncCmd { - private static final String s_name = "deletenuagevspdeviceresponse"; + public static final String APINAME = "deleteNuageVspDevice"; + @Inject NuageVspManager _nuageVspManager; @@ -83,7 +89,7 @@ public class DeleteNuageVspDeviceCmd extends BaseAsyncCmd { @Override public String getCommandName() { - return s_name; + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; } @Override http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/IssueNuageVspResourceRequestCmd.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/IssueNuageVspResourceRequestCmd.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/IssueNuageVspResourceRequestCmd.java deleted file mode 100644 index 559b30d..0000000 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/IssueNuageVspResourceRequestCmd.java +++ /dev/null @@ -1,213 +0,0 @@ -// -// 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.agent.AgentManager; -import com.cloud.agent.api.VspResourceAnswer; -import com.cloud.agent.api.VspResourceCommand; -import com.cloud.api.response.NuageVspResourceResponse; -import com.cloud.domain.dao.DomainDao; -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.host.HostVO; -import com.cloud.host.dao.HostDao; -import com.cloud.network.NuageVspDeviceVO; -import com.cloud.network.dao.NuageVspDao; -import com.cloud.offering.NetworkOffering; -import com.cloud.user.Account; -import com.cloud.user.AccountManager; -import org.apache.cloudstack.api.APICommand; -import org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.ApiErrorCode; -import org.apache.cloudstack.api.BaseCmd; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.response.NetworkOfferingResponse; -import org.apache.cloudstack.api.response.PhysicalNetworkResponse; -import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.cloudstack.context.CallContext; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; - -import javax.inject.Inject; -import java.util.List; - -@APICommand(name = "issueNuageVspResourceRequest", responseObject = NuageVspResourceResponse.class, description = "Issues a Nuage VSP REST API resource request", since = "4.5") -public class IssueNuageVspResourceRequestCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(IssueNuageVspResourceRequestCmd.class.getName()); - private static final String s_name = "nuagevspresourceresponse"; - - @Inject - protected AccountManager _accountMgr; - @Inject - protected DomainDao _domainDao; - @Inject - protected NuageVspDao _nuageConfigDao; - @Inject - HostDao _hostDao; - @Inject - AgentManager _agentMgr; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - - @Parameter(name = ApiConstants.NETWORK_OFFERING_ID, type = CommandType.UUID, entityType = NetworkOfferingResponse.class, required = true, description = "the network offering id") - private Long networkOfferingId; - - @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the Zone ID for the network") - private Long zoneId; - - @Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, description = "the ID of the physical network in to which Nuage VSP Controller is added") - private Long physicalNetworkId; - - @Parameter(name = VspConstants.NUAGE_VSP_API_METHOD, type = CommandType.STRING, required = true, description = "the Nuage VSP REST API method type") - private String method; - - @Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE, type = CommandType.STRING, required = true, description = "the resource in Nuage VSP") - private String resource; - - @Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE_ID, type = CommandType.STRING, description = "the ID of the resource in Nuage VSP") - private String resourceId; - - @Parameter(name = VspConstants.NUAGE_VSP_API_CHILD_RESOURCE, type = CommandType.STRING, description = "the child resource in Nuage VSP") - private String childResource; - - @Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE_FILTER, type = CommandType.STRING, description = "the resource filter in Nuage VSP") - private String resourceFilter; - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - - public Long getNetworkOfferingId() { - return networkOfferingId; - } - - public Long getZoneId() { - Long physicalNetworkId = getPhysicalNetworkId(); - - if (physicalNetworkId == null && zoneId == null) { - throw new InvalidParameterValueException("Zone id is required"); - } - - return zoneId; - } - - public Long getPhysicalNetworkId() { - if (physicalNetworkId != null) { - return physicalNetworkId; - } - - NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, networkOfferingId); - if (offering == null) { - throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId); - } - - if (zoneId == null) { - throw new InvalidParameterValueException("ZoneId is required as physicalNetworkId is null"); - } - return _networkService.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType()); - } - - public String getMethod() { - return method; - } - - public void setMethod(String method) { - this.method = method; - } - - public String getResource() { - return resource; - } - - public void setResource(String resource) { - this.resource = resource; - } - - public String getResourceId() { - return resourceId; - } - - public void setResourceId(String resourceId) { - this.resourceId = resourceId; - } - - public String getChildResource() { - return childResource; - } - - public void setChildResource(String childResource) { - this.childResource = childResource; - } - - public String getResourceFilter() { - return resourceFilter; - } - - public void setResourceFilter(String resourceFilter) { - this.resourceFilter = resourceFilter; - } - - @Override - public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - long accountId = CallContext.current().getCallingAccount().getAccountId(); - Account account = _accountMgr.getAccount(accountId); - - List<NuageVspDeviceVO> nuageVspDevices = _nuageConfigDao.listByPhysicalNetwork(getPhysicalNetworkId()); - if (nuageVspDevices != null && (!nuageVspDevices.isEmpty())) { - NuageVspDeviceVO config = nuageVspDevices.iterator().next(); - HostVO nuageVspHost = _hostDao.findById(config.getHostId()); - VspResourceCommand cmd = new VspResourceCommand(method, resource, resourceId, childResource, null, resourceFilter, null, null); - VspResourceAnswer answer = (VspResourceAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd); - if (answer == null || !answer.getResult()) { - s_logger.error("VspResourceCommand failed"); - if ((null != answer) && (null != answer.getDetails())) { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, answer.getDetails()); - } - } else { - NuageVspResourceResponse response = new NuageVspResourceResponse(); - response.setResourceInfo(StringUtils.isBlank(answer.getResourceInfo()) ? "" : answer.getResourceInfo()); - response.setObjectName("nuagevspresource"); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } - } else { - String errorMessage = "No Nuage VSP Controller configured on physical network " + getPhysicalNetworkId(); - s_logger.error(errorMessage); - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage); - } - } - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public long getEntityOwnerId() { - return CallContext.current().getCallingAccount().getId(); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java index 2d08e12..d9f80e7 100644 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java @@ -28,9 +28,11 @@ 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.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; @@ -41,9 +43,13 @@ import javax.inject.Inject; import java.util.ArrayList; import java.util.List; -@APICommand(name = "listNuageVspDevices", responseObject = NuageVspDeviceResponse.class, description = "Lists Nuage VSP devices", since = "4.5") +@APICommand(name = ListNuageVspDevicesCmd.APINAME, description = "Lists Nuage VSP devices", responseObject = NuageVspDeviceResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + since = "4.5", + authorized = {RoleType.Admin}) public class ListNuageVspDevicesCmd extends BaseListCmd { - private static final String s_name = "listnuagevspdeviceresponse"; + public static final String APINAME = "listNuageVspDevices"; + @Inject NuageVspManager _nuageVspManager; @@ -99,7 +105,7 @@ public class ListNuageVspDevicesCmd extends BaseListCmd { @Override public String getCommandName() { - return s_name; + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/UpdateNuageVspDeviceCmd.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/UpdateNuageVspDeviceCmd.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/UpdateNuageVspDeviceCmd.java index d235b2b..4197bd6 100755 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/UpdateNuageVspDeviceCmd.java +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/UpdateNuageVspDeviceCmd.java @@ -29,6 +29,7 @@ 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.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -38,14 +39,15 @@ 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", since = "4.6") +@APICommand(name = UpdateNuageVspDeviceCmd.APINAME, description = "Update a Nuage VSP device", responseObject = NuageVspDeviceResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + since = "4.6", + authorized = {RoleType.Admin}) public class UpdateNuageVspDeviceCmd extends BaseAsyncCmd { - private static final Logger s_logger = Logger.getLogger(UpdateNuageVspDeviceCmd.class); - private static final String s_name = "updatenuagevspdeviceresponse"; + public static final String APINAME = "updateNuageVspDevice"; @Inject NuageVspManager _nuageVspManager; @@ -160,7 +162,7 @@ public class UpdateNuageVspDeviceCmd extends BaseAsyncCmd { @Override public String getCommandName() { - return s_name; + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; } @Override http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java index d0d5ad2..531c828 100644 --- a/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java +++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java @@ -74,14 +74,12 @@ import com.cloud.network.vpc.VpcOfferingServiceMapVO; import com.cloud.network.vpc.dao.VpcDao; import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao; import com.cloud.offering.NetworkOffering; -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.ResourceStateAdapter; import com.cloud.resource.ServerResource; import com.cloud.resource.UnableDeleteHostException; -import com.cloud.util.NuageVspUtil; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.NicProfile; @@ -91,11 +89,18 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.NicDao; import com.google.common.base.Function; import com.google.common.collect.Lists; +import com.cloud.util.NuageVspEntityBuilder; +import net.nuage.vsp.acs.client.api.model.VspAclRule; +import net.nuage.vsp.acs.client.api.model.VspNetwork; +import net.nuage.vsp.acs.client.api.model.VspStaticNat; import org.apache.cloudstack.api.InternalIdentity; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.network.ExternalNetworkDeviceManager; +import org.apache.cloudstack.resourcedetail.VpcDetailVO; +import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao; import org.apache.log4j.Logger; +import javax.annotation.Nullable; import javax.inject.Inject; import javax.naming.ConfigurationException; import java.util.ArrayList; @@ -126,9 +131,9 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider @Inject NetworkDao _networkDao; @Inject - protected DomainDao _domainDao; + DomainDao _domainDao; @Inject - protected DataCenterDao _dcDao; + DataCenterDao _dcDao; @Inject IPAddressDao _ipAddressDao; @Inject @@ -157,6 +162,10 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider PhysicalNetworkDao _physicalNetworkDao; @Inject NetworkACLItemDao _networkACLItemDao; + @Inject + NuageVspEntityBuilder _nuageVspEntityBuilder; + @Inject + VpcDetailsDao _vpcDetailsDao; @Override public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> service) throws ResourceUnavailableException { @@ -242,53 +251,21 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider return false; } - 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<Map<String, Object>> ingressFirewallRules = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Ingress, egressDefaultPolicy); - List<Map<String, Object>> egressFirewallRules = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Egress, egressDefaultPolicy); + VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false); + List<String> dnsServers = _nuageVspManager.getDnsDetails(network); + List<VspAclRule> ingressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Ingress); + List<VspAclRule> egressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Egress); List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId()); - List<String> acsFipUuid = new ArrayList<String>(); + List<String> floatingIpUuids = new ArrayList<String>(); for (IPAddressVO ip : ips) { - acsFipUuid.add(ip.getUuid()); + floatingIpUuids.add(ip.getUuid()); } 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); - Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build()); + ImplementVspCommand cmd = new ImplementVspCommand(vspNetwork, dnsServers, ingressFirewallRules, egressFirewallRules, floatingIpUuids); + Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("ImplementVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname")); if ((null != answer) && (null != answer.getDetails())) { @@ -302,23 +279,21 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider private boolean applyACLRulesForVpc(Network network, NetworkOffering offering) throws ResourceUnavailableException { List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(network.getNetworkACLId()); if (_networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.NetworkACL)) { - applyACLRules(network, rules, true, null, false); + applyACLRules(network, rules, true, false); } return true; } - private List<Map<String, Object>> getFirewallRulesToApply(long networkId, FirewallRule.TrafficType trafficType, final boolean egressDefaultPolicy) { - List<FirewallRuleVO> firewallRulesToApply = _firewallRulesDao.listByNetworkPurposeTrafficType(networkId, FirewallRule.Purpose.Firewall, trafficType); + private List<VspAclRule> getFirewallRulesToApply(final Network network, FirewallRule.TrafficType trafficType) { + List<FirewallRuleVO> firewallRulesToApply = _firewallRulesDao.listByNetworkPurposeTrafficType(network.getId(), FirewallRule.Purpose.Firewall, trafficType); + List<VspAclRule> vspAclRulesToApply = Lists.newArrayListWithExpectedSize(firewallRulesToApply.size()); + for (FirewallRuleVO rule : firewallRulesToApply) { - // load cidrs if any rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId())); + VspAclRule vspAclRule = _nuageVspEntityBuilder.buildVspAclRule(rule, network); + vspAclRulesToApply.add(vspAclRule); } - return Lists.transform(firewallRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() { - @Override - public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) { - return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy); - } - }); + return vspAclRulesToApply; } @Override @@ -463,48 +438,19 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider @Override public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException { - //Check if the network is associated to a VPC - Long vpcId = config.getVpcId(); - String vpcOrSubnetUuid = null; - if (vpcId != null) { - Vpc vpcObj = _vpcDao.findById(vpcId); - vpcOrSubnetUuid = vpcObj.getUuid(); - } else { - vpcOrSubnetUuid = config.getUuid(); - } - Domain networkDomain = _domainDao.findById(config.getDomainId()); - - long networkOfferingId = _ntwkOfferingDao.findById(config.getNetworkOfferingId()).getId(); - boolean isL3Network = isL3Network(networkOfferingId); - - List<Map<String, Object>> sourceNatDetails = new ArrayList<Map<String, Object>>(); + List<VspStaticNat> vspStaticNatDetails = new ArrayList<VspStaticNat>(); for (StaticNat staticNat : rules) { - Map<String, Object> sourceNatDetail = new HashMap<String, Object>(); IPAddressVO sourceNatIp = _ipAddressDao.findById(staticNat.getSourceIpAddressId()); - VlanVO sourceNatVan = _vlanDao.findById(sourceNatIp.getVlanId()); + VlanVO sourceNatVlan = _vlanDao.findById(sourceNatIp.getVlanId()); NicVO nicVO = _nicDao.findByIp4AddressAndNetworkId(staticNat.getDestIpAddress(), staticNat.getNetworkId()); - //Just get all the information about the sourceNat which will be used by NuageVsp - //client to process the request - sourceNatDetail.put("sourceNatIpUuid", sourceNatIp.getUuid()); - sourceNatDetail.put("sourceNatIpAddress", sourceNatIp.getAddress().addr()); - sourceNatDetail.put("nicUuid", nicVO == null ? null : nicVO.getUuid()); - sourceNatDetail.put("nicMacAddress", nicVO == null ? null : nicVO.getMacAddress()); - sourceNatDetail.put("isRevoke", staticNat.isForRevoke()); - sourceNatDetail.put("sourceNatVlanUuid", sourceNatVan.getUuid()); - sourceNatDetail.put("sourceNatVlanGateway", sourceNatVan.getVlanGateway()); - sourceNatDetail.put("sourceNatVlanNetmask", sourceNatVan.getVlanNetmask()); - sourceNatDetails.add(sourceNatDetail); + VspStaticNat vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(staticNat.isForRevoke(), sourceNatIp, sourceNatVlan, nicVO); + vspStaticNatDetails.add(vspStaticNat); } + VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(config, false); 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); - Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build()); + ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(vspNetwork, vspStaticNatDetails); + Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname")); if ((null != answer) && (null != answer.getDetails())) { @@ -534,44 +480,27 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider } s_logger.info("Applying " + rules.size() + " Firewall Rules for network " + network.getName()); - return applyACLRules(network, rules, false, rules.iterator().next().getTrafficType().equals(FirewallRule.TrafficType.Ingress), false); + return applyACLRules(network, rules, false, false); } - protected boolean applyACLRules(Network network, List<? extends InternalIdentity> rules, boolean isNetworkAcl, Boolean isAcsIngressAcl, boolean networkReset) + protected boolean applyACLRules(final Network network, List<? extends InternalIdentity> rules, boolean isNetworkAcl, boolean networkReset) throws ResourceUnavailableException { - Domain networksDomain = _domainDao.findById(network.getDomainId()); - NetworkOfferingVO networkOfferingVO = _ntwkOfferingDao.findById(network.getNetworkOfferingId()); - Long vpcId = network.getVpcId(); - String vpcOrSubnetUuid = null; - if (vpcId != null) { - Vpc vpcObj = _vpcDao.findById(vpcId); - vpcOrSubnetUuid = vpcObj.getUuid(); - } else { - vpcOrSubnetUuid = network.getUuid(); - } - boolean egressDefaultPolicy = networkOfferingVO.getEgressDefaultPolicy(); - List<Map<String, Object>> aclRules = new ArrayList<Map<String, Object>>(); - for (InternalIdentity acl : rules) { - aclRules.add(getACLRuleDetails(acl, egressDefaultPolicy)); - } + VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false); + List<VspAclRule> vspAclRules = Lists.transform(rules, new Function<InternalIdentity, VspAclRule>() { + @Nullable + @Override + public VspAclRule apply(@Nullable InternalIdentity input) { + if (input instanceof FirewallRule) { + return _nuageVspEntityBuilder.buildVspAclRule((FirewallRule) input, network); + } + return _nuageVspEntityBuilder.buildVspAclRule((NetworkACLItem) input); + } + }); - boolean isL3Network = isL3Network(network.getNetworkOfferingId()); HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId()); - String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, networkOfferingVO); - ApplyAclRuleVspCommand.Builder cmdBuilder = new ApplyAclRuleVspCommand.Builder() - .networkAcl(isNetworkAcl) - .networkUuid(network.getUuid()) - .networkDomainUuid(networksDomain.getUuid()) - .vpcOrSubnetUuid(vpcOrSubnetUuid) - .networkName(network.getName()) - .isL2Network(!isL3Network) - .aclRules(aclRules) - .networkId(network.getId()) - .egressDefaultPolicy(networkOfferingVO.getEgressDefaultPolicy()) - .acsIngressAcl(isAcsIngressAcl) - .networkReset(networkReset) - .domainTemplateName(preConfiguredDomainTemplateName); - Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build()); + VspAclRule.ACLType vspAclType = isNetworkAcl ? VspAclRule.ACLType.NetworkACL : VspAclRule.ACLType.Firewall; + ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(vspAclType, vspNetwork, vspAclRules, networkReset); + Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("ApplyAclRuleNuageVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname")); if ((null != answer) && (null != answer.getDetails())) { @@ -594,7 +523,7 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider } if (rules != null) { s_logger.info("Applying " + rules.size() + " Network ACLs for network " + config.getName()); - applyACLRules(config, rules, true, null, rules.isEmpty()); + applyACLRules(config, rules, true, rules.isEmpty()); } return true; } @@ -625,12 +554,17 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider if (vpc.getState().equals(Vpc.State.Inactive)) { Domain vpcDomain = _domainDao.findById(vpc.getDomainId()); HostVO nuageVspHost = getNuageVspHost(getPhysicalNetworkId(vpc.getZoneId())); - String preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key()); - ShutDownVpcVspCommand.Builder cmdBuilder = new ShutDownVpcVspCommand.Builder() - .domainUuid(vpcDomain.getUuid()) - .vpcUuid(vpc.getUuid()) - .domainTemplateName(preConfiguredDomainTemplateName); - Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build()); + + String preConfiguredDomainTemplateName; + VpcDetailVO domainTemplateNameDetail = _vpcDetailsDao.findDetail(vpc.getId(), NuageVspManager.nuageDomainTemplateDetailName); + if (domainTemplateNameDetail != null) { + preConfiguredDomainTemplateName = domainTemplateNameDetail.getValue(); + } else { + preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key()); + } + + ShutDownVpcVspCommand cmd = new ShutDownVpcVspCommand(vpcDomain.getUuid(), vpc.getUuid(), preConfiguredDomainTemplateName); + Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("ShutDownVpcVspCommand for VPC " + vpc.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname")); if ((null != answer) && (null != answer.getDetails())) { @@ -707,50 +641,4 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider } return nuageVspHost; } - - protected boolean isL3Network(Long offeringId) { - return _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.SourceNat) - || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.StaticNat); - } - - private Map<String, Object> getACLRuleDetails(Object aclRule, boolean egressDefaultPolicy) { - Map<String, Object> aclDetails = new HashMap<String, Object>(); - if (aclRule instanceof FirewallRule) { - FirewallRule firewallRule = (FirewallRule)aclRule; - aclDetails.put("sourceCidrList", firewallRule.getSourceCidrList()); - aclDetails.put("uuid", firewallRule.getUuid()); - aclDetails.put("protocol", firewallRule.getProtocol()); - aclDetails.put("startPort", firewallRule.getSourcePortStart()); - aclDetails.put("endPort", firewallRule.getSourcePortEnd()); - aclDetails.put("state", firewallRule.getState().name()); - aclDetails.put("trafficType", firewallRule.getTrafficType().name()); - if (firewallRule.getSourceIpAddressId() != null) { - //add the source IP - IPAddressVO ipaddress = _ipAddressDao.findById(((FirewallRule)aclRule).getSourceIpAddressId()); - aclDetails.put("sourceIpAddress", ipaddress != null ? ipaddress.getVmIp() + "/32" : null); - } - if (firewallRule.getTrafficType().equals(FirewallRule.TrafficType.Egress) && egressDefaultPolicy) { - aclDetails.put("action", "Deny"); - } else { - aclDetails.put("action", "Allow"); - } - aclDetails.put("priority", -1); - aclDetails.put("type", "Firewall"); - } else { - NetworkACLItem networkAcl = (NetworkACLItem)aclRule; - aclDetails.put("sourceCidrList", networkAcl.getSourceCidrList()); - aclDetails.put("uuid", networkAcl.getUuid()); - aclDetails.put("protocol", networkAcl.getProtocol()); - aclDetails.put("startPort", networkAcl.getSourcePortStart()); - aclDetails.put("endPort", networkAcl.getSourcePortEnd()); - aclDetails.put("state", networkAcl.getState().name()); - aclDetails.put("trafficType", networkAcl.getTrafficType().name()); - //Set sourceIP to null as it is not applicable - aclDetails.put("sourceIpAddress", null); - aclDetails.put("action", networkAcl.getAction().name()); - aclDetails.put("priority", networkAcl.getNumber()); - aclDetails.put("type", "NetworkACL"); - } - return aclDetails; - } } \ No newline at end of file
