From 8bd1eaa210f67f1347e7ecc4406e48d29783ca3d Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Fri, 8 Nov 2013 10:37:45 -0800 Subject: [PATCH] ResourceMetaData: added support for userIpAddress (publicIp) metadata --- api/src/com/cloud/server/ResourceTag.java | 2 +- ...spring-engine-schema-core-daos-context.xml | 2 + .../resourcedetail/FirewallRuleDetailVO.java | 78 +++++++++--------- .../resourcedetail/UserIpAddressDetailVO.java | 80 +++++++++++++++++++ .../dao/UserIpAddressDetailsDao.java | 26 ++++++ .../dao/UserIpAddressDetailsDaoImpl.java | 35 ++++++++ .../metadata/ResourceMetaDataManagerImpl.java | 6 +- setup/db/db/schema-421to430.sql | 10 +++ 8 files changed, 198 insertions(+), 41 deletions(-) create mode 100644 engine/schema/src/org/apache/cloudstack/resourcedetail/UserIpAddressDetailVO.java create mode 100644 engine/schema/src/org/apache/cloudstack/resourcedetail/dao/UserIpAddressDetailsDao.java create mode 100644 engine/schema/src/org/apache/cloudstack/resourcedetail/dao/UserIpAddressDetailsDaoImpl.java diff --git a/api/src/com/cloud/server/ResourceTag.java b/api/src/com/cloud/server/ResourceTag.java index ab74d260dc3..47e00be68b3 100644 --- a/api/src/com/cloud/server/ResourceTag.java +++ b/api/src/com/cloud/server/ResourceTag.java @@ -35,7 +35,7 @@ public interface ResourceTag extends ControlledEntity, Identity, InternalIdentit PortForwardingRule (true, false), FirewallRule (true, true), SecurityGroup (true, false), - PublicIpAddress (true, false), + PublicIpAddress (true, true), Project (true, false), Vpc (true, false), NetworkACL (true, false), diff --git a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml index c71190b5cf5..0a5ae5028b4 100644 --- a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml +++ b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -321,6 +321,8 @@ + + diff --git a/engine/schema/src/org/apache/cloudstack/resourcedetail/FirewallRuleDetailVO.java b/engine/schema/src/org/apache/cloudstack/resourcedetail/FirewallRuleDetailVO.java index 88d2b0096bb..a2ec6ff0bb4 100644 --- a/engine/schema/src/org/apache/cloudstack/resourcedetail/FirewallRuleDetailVO.java +++ b/engine/schema/src/org/apache/cloudstack/resourcedetail/FirewallRuleDetailVO.java @@ -28,53 +28,53 @@ import org.apache.cloudstack.api.ResourceDetail; @Entity @Table(name="firewall_rule_details") public class FirewallRuleDetailVO implements ResourceDetail{ - @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) - @Column(name="id") - private long id; + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name="id") + private long id; - @Column(name="firewall_rule_id") - private long resourceId; + @Column(name="firewall_rule_id") + private long resourceId; - @Column(name="name") - private String name; + @Column(name="name") + private String name; - @Column(name="value", length=1024) - private String value; - - @Column(name="display") - private boolean display; + @Column(name="value", length=1024) + private String value; + + @Column(name="display") + private boolean display; - public FirewallRuleDetailVO() {} + public FirewallRuleDetailVO() {} - public FirewallRuleDetailVO(long networkId, String name, String value) { - this.resourceId = networkId; - this.name = name; - this.value = value; - } + public FirewallRuleDetailVO(long networkId, String name, String value) { + this.resourceId = networkId; + this.name = name; + this.value = value; + } - @Override - public long getId() { - return id; - } + @Override + public long getId() { + return id; + } - @Override - public String getName() { - return name; - } + @Override + public String getName() { + return name; + } - @Override - public String getValue() { - return value; - } + @Override + public String getValue() { + return value; + } - @Override - public long getResourceId() { - return resourceId; - } + @Override + public long getResourceId() { + return resourceId; + } - @Override - public boolean isDisplay() { - return display; - } + @Override + public boolean isDisplay() { + return display; + } } diff --git a/engine/schema/src/org/apache/cloudstack/resourcedetail/UserIpAddressDetailVO.java b/engine/schema/src/org/apache/cloudstack/resourcedetail/UserIpAddressDetailVO.java new file mode 100644 index 00000000000..56a47c2226f --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/resourcedetail/UserIpAddressDetailVO.java @@ -0,0 +1,80 @@ +// 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 org.apache.cloudstack.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; + +import org.apache.cloudstack.api.ResourceDetail; + +@Entity +@Table(name="user_ip_address_details") +public class UserIpAddressDetailVO implements ResourceDetail{ + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name="id") + private long id; + + @Column(name="user_ip_address_id") + private long resourceId; + + @Column(name="name") + private String name; + + @Column(name="value", length=1024) + private String value; + + @Column(name="display") + private boolean display; + + public UserIpAddressDetailVO() {} + + public UserIpAddressDetailVO(long networkId, String name, String value) { + this.resourceId = networkId; + this.name = name; + this.value = value; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getValue() { + return value; + } + + @Override + public long getResourceId() { + return resourceId; + } + + @Override + public boolean isDisplay() { + return display; + } +} diff --git a/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/UserIpAddressDetailsDao.java b/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/UserIpAddressDetailsDao.java new file mode 100644 index 00000000000..856f5089578 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/UserIpAddressDetailsDao.java @@ -0,0 +1,26 @@ +// 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 org.apache.cloudstack.resourcedetail.dao; + +import org.apache.cloudstack.resourcedetail.ResourceDetailsDao; +import org.apache.cloudstack.resourcedetail.UserIpAddressDetailVO; + +import com.cloud.utils.db.GenericDao; + +public interface UserIpAddressDetailsDao extends GenericDao, ResourceDetailsDao{ + +} diff --git a/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/UserIpAddressDetailsDaoImpl.java b/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/UserIpAddressDetailsDaoImpl.java new file mode 100644 index 00000000000..c1cb137ec03 --- /dev/null +++ b/engine/schema/src/org/apache/cloudstack/resourcedetail/dao/UserIpAddressDetailsDaoImpl.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 +// 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 org.apache.cloudstack.resourcedetail.dao; + +import javax.ejb.Local; + +import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase; +import org.apache.cloudstack.resourcedetail.UserIpAddressDetailVO; +import org.springframework.stereotype.Component; + + +@Component +@Local (value={UserIpAddressDetailsDao.class}) +public class UserIpAddressDetailsDaoImpl extends ResourceDetailsDaoBase implements UserIpAddressDetailsDao { + + @Override + public void addDetail(long resourceId, String key, String value) { + super.addDetail(new UserIpAddressDetailVO(resourceId, key, value)); + } +} + diff --git a/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java b/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java index 5f7ad4ba9a8..4ebc43e505f 100644 --- a/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java +++ b/server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java @@ -27,6 +27,7 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.ResourceDetail; import org.apache.cloudstack.resourcedetail.ResourceDetailsDao; import org.apache.cloudstack.resourcedetail.dao.FirewallRuleDetailsDao; +import org.apache.cloudstack.resourcedetail.dao.UserIpAddressDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -75,6 +76,8 @@ public class ResourceMetaDataManagerImpl extends ManagerBase implements Resource StoragePoolDetailsDao _storageDetailsDao; @Inject FirewallRuleDetailsDao _firewallRuleDetailsDao; + @Inject + UserIpAddressDetailsDao _userIpAddressDetailsDao; private static Map> _daoMap= new HashMap>(); @@ -91,7 +94,8 @@ public class ResourceMetaDataManagerImpl extends ManagerBase implements Resource _daoMap.put(ResourceObjectType.Zone, _dcDetailsDao); _daoMap.put(ResourceObjectType.Storage, _storageDetailsDao); _daoMap.put(ResourceObjectType.FirewallRule, _firewallRuleDetailsDao); - + _daoMap.put(ResourceObjectType.PublicIpAddress, _userIpAddressDetailsDao); + return true; } diff --git a/setup/db/db/schema-421to430.sql b/setup/db/db/schema-421to430.sql index dbfab4a5bb8..8b0d136b0e0 100644 --- a/setup/db/db/schema-421to430.sql +++ b/setup/db/db/schema-421to430.sql @@ -619,3 +619,13 @@ CREATE TABLE `cloud`.`usage_event_details` ( PRIMARY KEY (`id`), CONSTRAINT `fk_usage_event_details__usage_event_id` FOREIGN KEY `fk_usage_event_details__usage_event_id`(`usage_event_id`) REFERENCES `usage_event`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`user_ip_address_details` ( + `id` bigint unsigned NOT NULL auto_increment, + `user_ip_address_id` bigint unsigned NOT NULL COMMENT 'User ip address id', + `name` varchar(255) NOT NULL, + `value` varchar(1024) NOT NULL, + `display` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'True if the detail can be displayed to the end user', + PRIMARY KEY (`id`), + CONSTRAINT `fk_user_ip_address_details__user_ip_address_id` FOREIGN KEY `fk_user_ip_address_details__user_ip_address_id`(`user_ip_address_id`) REFERENCES `user_ip_address`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8;