CLOUDSTACK-4854: Add support for adding network details Signed off by : nitin mehta<nitin.me...@citrix.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/fa0c685b Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/fa0c685b Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/fa0c685b Branch: refs/heads/ui-restyle Commit: fa0c685bcb89c8d7a7cf8939f5237887a7c9f4ff Parents: 90cc0d8 Author: Nitin Mehta <nitin.me...@citrix.com> Authored: Thu Oct 10 19:18:39 2013 -0700 Committer: Nitin Mehta <nitin.me...@citrix.com> Committed: Thu Oct 10 19:18:39 2013 -0700 ---------------------------------------------------------------------- client/tomcatconf/applicationContext.xml.in | 1 + .../com/cloud/network/dao/NetworkDetailVO.java | 90 +++++++++++++++++++ .../cloud/network/dao/NetworkDetailsDao.java | 35 ++++++++ .../network/dao/NetworkDetailsDaoImpl.java | 93 ++++++++++++++++++++ .../com/cloud/api/query/QueryManagerImpl.java | 12 ++- .../metadata/ResourceMetaDataManagerImpl.java | 12 ++- 6 files changed, 240 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa0c685b/client/tomcatconf/applicationContext.xml.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in index 6dda5c7..2a3520b 100644 --- a/client/tomcatconf/applicationContext.xml.in +++ b/client/tomcatconf/applicationContext.xml.in @@ -268,6 +268,7 @@ <bean id="networkACLItemDaoImpl" class="com.cloud.network.vpc.dao.NetworkACLItemDaoImpl" /> <bean id="networkDaoImpl" class="com.cloud.network.dao.NetworkDaoImpl" /> <bean id="networkDomainDaoImpl" class="com.cloud.network.dao.NetworkDomainDaoImpl" /> + <bean id="networkDetailsDaoImpl" class="com.cloud.network.dao.NetworkDetailsDaoImpl" /> <bean id="networkExternalFirewallDaoImpl" class="com.cloud.network.dao.NetworkExternalFirewallDaoImpl" /> <bean id="networkExternalLoadBalancerDaoImpl" class="com.cloud.network.dao.NetworkExternalLoadBalancerDaoImpl" /> <bean id="networkOfferingDaoImpl" class="com.cloud.offerings.dao.NetworkOfferingDaoImpl" /> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa0c685b/engine/schema/src/com/cloud/network/dao/NetworkDetailVO.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDetailVO.java b/engine/schema/src/com/cloud/network/dao/NetworkDetailVO.java new file mode 100644 index 0000000..6292397 --- /dev/null +++ b/engine/schema/src/com/cloud/network/dao/NetworkDetailVO.java @@ -0,0 +1,90 @@ +// 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.network.dao; + +import org.apache.cloudstack.api.InternalIdentity; +import org.apache.cloudstack.api.ResourceDetail; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="network_details") +public class NetworkDetailVO implements InternalIdentity, ResourceDetail { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name="id") + private long id; + + @Column(name="network_id") + private long networkId; + + @Column(name="name") + private String name; + + @Column(name="value", length=1024) + private String value; + + public NetworkDetailVO() {} + + public NetworkDetailVO(long networkId, String name, String value) { + this.networkId = networkId; + this.name = name; + this.value = value; + } + + public long getId() { + return id; + } + + public long getNetworkId() { + return networkId; + } + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + + public void setId(long id) { + this.id = id; + } + + public void setNetworkId(long networkId) { + this.networkId = networkId; + } + + public void setName(String name) { + this.name = name; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public long getResourceDetail() { + return networkId; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa0c685b/engine/schema/src/com/cloud/network/dao/NetworkDetailsDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDetailsDao.java b/engine/schema/src/com/cloud/network/dao/NetworkDetailsDao.java new file mode 100644 index 0000000..f788534 --- /dev/null +++ b/engine/schema/src/com/cloud/network/dao/NetworkDetailsDao.java @@ -0,0 +1,35 @@ +// 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 +// 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.network.dao; + +import com.cloud.utils.db.GenericDao; + +import java.util.List; +import java.util.Map; + +public interface NetworkDetailsDao extends GenericDao<NetworkDetailVO, Long> { + List<NetworkDetailVO> findDetails(long networkId); + + void persist(long networkId, Map<String, String> details); + + NetworkDetailVO findDetail(long networkId, String name); + + void deleteDetails(long networkId); + + public void removeDetails(Long networkId, String key); + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa0c685b/engine/schema/src/com/cloud/network/dao/NetworkDetailsDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDetailsDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkDetailsDaoImpl.java new file mode 100644 index 0000000..453a95a --- /dev/null +++ b/engine/schema/src/com/cloud/network/dao/NetworkDetailsDaoImpl.java @@ -0,0 +1,93 @@ +// 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 +// 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.network.dao; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.network.dao.NetworkDetailVO; +import com.cloud.vm.dao.UserVmDetailsDao; +import org.springframework.stereotype.Component; + +import javax.ejb.Local; +import java.util.List; +import java.util.Map; + +@Component +@Local(value=NetworkDetailsDao.class) +public class NetworkDetailsDaoImpl extends GenericDaoBase<NetworkDetailVO, Long> implements NetworkDetailsDao { + + protected final SearchBuilder<NetworkDetailVO> NetworkSearch; + protected final SearchBuilder<NetworkDetailVO> DetailSearch; + + public NetworkDetailsDaoImpl() { + NetworkSearch = createSearchBuilder(); + NetworkSearch.and("networkId", NetworkSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + NetworkSearch.done(); + + DetailSearch = createSearchBuilder(); + DetailSearch.and("networkId", DetailSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ); + DetailSearch.done(); + } + + + @Override + public List<NetworkDetailVO> findDetails(long networkId) { + SearchCriteria<NetworkDetailVO> sc = NetworkSearch.create(); + sc.setParameters("networkId", networkId); + + List<NetworkDetailVO> results = search(sc, null); + return results; + } + + @Override + public void persist(long networkId, Map<String, String> details) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public NetworkDetailVO findDetail(long networkId, String name) { + SearchCriteria<NetworkDetailVO> sc = DetailSearch.create(); + sc.setParameters("networkId", networkId); + sc.setParameters("name", name); + + return findOneBy(sc); } + + @Override + public void deleteDetails(long networkId) { + SearchCriteria<NetworkDetailVO> sc = NetworkSearch.create(); + sc.setParameters("networkId", networkId); + + List<NetworkDetailVO> results = search(sc, null); + for (NetworkDetailVO result : results) { + remove(result.getId()); + } + } + + @Override + public void removeDetails(Long networkId, String key) { + if(key != null){ + NetworkDetailVO detail = findDetail(networkId, key); + if(detail != null){ + remove(detail.getId()); + } + }else { + deleteDetails(networkId); + } + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa0c685b/server/src/com/cloud/api/query/QueryManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 3b247fa..e65a8b8 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -26,6 +26,7 @@ import java.util.Set; import javax.ejb.Local; import javax.inject.Inject; +import com.cloud.network.dao.NetworkDetailsDao; import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO; import org.apache.cloudstack.affinity.AffinityGroupResponse; @@ -332,6 +333,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { @Inject AffinityGroupDomainMapDao _affinityGroupDomainMapDao; + @Inject + NetworkDetailsDao _networkDetailsDao; + /* * (non-Javadoc) * @@ -3250,7 +3254,13 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } else { requestedDetail = _dcDetailsDao.findDetail(id, key); } - } else { + } else if (resourceType == TaggedResourceType.Network){ + if (key == null) { + detailList = _networkDetailsDao.findDetails(id); + } else { + requestedDetail = _networkDetailsDao.findDetail(id, key); + } + }else { throw new UnsupportedServiceException("Resource type " + resourceType + " is not supported by the cloudStack"); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa0c685b/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java b/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java index 8367863..5481ebb 100644 --- a/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java +++ b/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java @@ -26,6 +26,8 @@ import javax.naming.ConfigurationException; import com.cloud.dc.DcDetailVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DcDetailsDao; +import com.cloud.network.dao.NetworkDetailVO; +import com.cloud.network.dao.NetworkDetailsDao; import com.cloud.server.ResourceMetaDataService; import com.cloud.storage.VolumeDetailVO; import com.cloud.storage.dao.VolumeDetailsDao; @@ -130,6 +132,8 @@ public class ResourceMetaDataManagerImpl extends ManagerBase implements Resource @Inject DcDetailsDao _dcDetailsDao; @Inject + NetworkDetailsDao _networkDetailsDao; + @Inject TaggedResourceService _taggedResourceMgr; @Inject UserVmDetailsDao _userVmDetail; @@ -219,6 +223,9 @@ public class ResourceMetaDataManagerImpl extends ManagerBase implements Resource } else if (resourceType == TaggedResourceType.Zone){ DcDetailVO dataCenterDetail = new DcDetailVO(id, key, value); _dcDetailsDao.persist(dataCenterDetail); + } else if (resourceType == TaggedResourceType.Network){ + NetworkDetailVO networkDetail = new NetworkDetailVO(id, key, value); + _networkDetailsDao.persist(networkDetail); } else { throw new InvalidParameterValueException("The resource type " + resourceType + " is not supported by the API yet"); } @@ -246,8 +253,9 @@ public class ResourceMetaDataManagerImpl extends ManagerBase implements Resource _userVmDetailDao.removeDetails(id, key); } else if (resourceType == TaggedResourceType.Zone){ _dcDetailsDao.removeDetails(id, key); - } - else{ + } else if (resourceType == TaggedResourceType.Network){ + _networkDetailsDao.removeDetails(id, key); + } else{ throw new InvalidParameterValueException("The resource type " + resourceType + " is not supported by the API yet"); }