cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject [05/57] [abbrv] [partial] merge master
Date Mon, 13 May 2013 12:25:35 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/offerings/NetworkOfferingServiceMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/NetworkOfferingServiceMapVO.java b/engine/schema/src/com/cloud/offerings/NetworkOfferingServiceMapVO.java
new file mode 100644
index 0000000..f249405
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/NetworkOfferingServiceMapVO.java
@@ -0,0 +1,94 @@
+// 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.offerings;
+
+import java.util.Date;
+
+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 com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="ntwk_offering_service_map")
+public class NetworkOfferingServiceMapVO implements InternalIdentity {
+   
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    long id;
+    
+    @Column(name="network_offering_id")
+    long networkOfferingId;
+    
+    @Column(name="service")
+    String service;
+    
+    @Column(name="provider")
+    String provider;
+    
+    @Column(name=GenericDao.CREATED_COLUMN)
+    Date created;
+
+    public long getId() {
+        return id;
+    }
+
+    public long getNetworkOfferingId() {
+        return networkOfferingId;
+    }
+
+    public String getService() {
+        return service;
+    }
+
+    public String getProvider() {
+        return provider;
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+    
+    public NetworkOfferingServiceMapVO() {
+    }
+    
+    public NetworkOfferingServiceMapVO(long networkOfferingId, Service service, Provider provider) {
+        this.networkOfferingId = networkOfferingId;
+        this.service = service.getName();
+        if (provider != null) {
+            this.provider = provider.getName();
+        }
+    }
+    
+    public String toString() {
+        StringBuilder buf = new StringBuilder("[Network Offering Service[");
+        return buf.append(networkOfferingId).append("-").append(service).append("-").append(provider).append("]").toString();
+    }
+}
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java b/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java
new file mode 100755
index 0000000..3ae0bf3
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java
@@ -0,0 +1,417 @@
+// 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.offerings;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.network.Network;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = "network_offerings")
+public class NetworkOfferingVO implements NetworkOffering {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    long id;
+
+    @Column(name = "name")
+    String name;
+
+    @Column(name = "unique_name")
+    private String uniqueName;
+
+    @Column(name = "display_text")
+    String displayText;
+
+    @Column(name = "nw_rate")
+    Integer rateMbps;
+
+    @Column(name = "mc_rate")
+    Integer multicastRateMbps;
+
+    @Column(name = "traffic_type")
+    @Enumerated(value = EnumType.STRING)
+    TrafficType trafficType;
+
+    @Column(name = "specify_vlan")
+    boolean specifyVlan;
+
+    @Column(name = "system_only")
+    boolean systemOnly;
+
+    @Column(name = "service_offering_id")
+    Long serviceOfferingId;
+
+    @Column(name = "tags", length = 4096)
+    String tags;
+
+    @Column(name = "default")
+    boolean isDefault;
+
+    @Column(name = "availability")
+    @Enumerated(value = EnumType.STRING)
+    Availability availability;
+
+    @Column(name = "state")
+    @Enumerated(value = EnumType.STRING)
+    State state = State.Disabled;
+
+    @Column(name = GenericDao.REMOVED_COLUMN)
+    Date removed;
+
+    @Column(name = GenericDao.CREATED_COLUMN)
+    Date created;
+
+    @Column(name = "guest_type")
+    @Enumerated(value = EnumType.STRING)
+    Network.GuestType guestType;
+
+    @Column(name = "dedicated_lb_service")
+    boolean dedicatedLB;
+
+    @Column(name = "shared_source_nat_service")
+    boolean sharedSourceNat;
+
+    @Column(name = "specify_ip_ranges")
+    boolean specifyIpRanges = false;
+
+    @Column(name = "sort_key")
+    int sortKey;
+
+    @Column(name = "uuid")
+    String uuid;
+
+    @Column(name = "redundant_router_service")
+    boolean redundantRouter;
+
+    @Column(name = "conserve_mode")
+    boolean conserveMode;
+
+    @Column(name = "elastic_ip_service")
+    boolean elasticIp;
+
+    @Column(name = "eip_associate_public_ip")
+    boolean eipAssociatePublicIp;
+
+    @Column(name = "elastic_lb_service")
+    boolean elasticLb;
+
+    @Column(name = "inline")
+    boolean inline;
+
+    @Column(name = "is_persistent")
+    boolean isPersistent;
+
+    @Override
+    public String getDisplayText() {
+        return displayText;
+    }
+    
+    @Column(name = "internal_lb")
+    boolean internalLb;
+    
+    @Column(name = "public_lb")
+    boolean publicLb;
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public TrafficType getTrafficType() {
+        return trafficType;
+    }
+
+    @Override
+    public Integer getMulticastRateMbps() {
+        return multicastRateMbps;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public Integer getRateMbps() {
+        return rateMbps;
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+
+    @Override
+    public boolean isSystemOnly() {
+        return systemOnly;
+    }
+
+    public Date getRemoved() {
+        return removed;
+    }
+
+    @Override
+    public String getTags() {
+        return tags;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setDisplayText(String displayText) {
+        this.displayText = displayText;
+    }
+
+    public void setRateMbps(Integer rateMbps) {
+        this.rateMbps = rateMbps;
+    }
+
+    public void setMulticastRateMbps(Integer multicastRateMbps) {
+        this.multicastRateMbps = multicastRateMbps;
+    }
+
+    @Override
+    public boolean isDefault() {
+        return isDefault;
+    }
+
+    @Override
+    public boolean getSpecifyVlan() {
+        return specifyVlan;
+    }
+
+    @Override
+    public Availability getAvailability() {
+        return availability;
+    }
+
+    public void setAvailability(Availability availability) {
+        this.availability = availability;
+    }
+
+    @Override
+    public String getUniqueName() {
+        return uniqueName;
+    }
+
+    @Override
+    public void setState(State state) {
+        this.state = state;
+    }
+
+    @Override
+    public State getState() {
+        return state;
+    }
+
+    @Override
+    public Network.GuestType getGuestType() {
+        return guestType;
+    }
+
+    public void setServiceOfferingId(Long serviceOfferingId) {
+        this.serviceOfferingId = serviceOfferingId;
+    }
+
+    @Override
+    public Long getServiceOfferingId() {
+        return serviceOfferingId;
+    }
+
+    @Override
+    public boolean getDedicatedLB() {
+        return dedicatedLB;
+    }
+
+    public void setDedicatedLB(boolean dedicatedLB) {
+        this.dedicatedLB = dedicatedLB;
+    }
+
+    @Override
+    public boolean getSharedSourceNat() {
+        return sharedSourceNat;
+    }
+
+    public void setSharedSourceNat(boolean sharedSourceNat) {
+        this.sharedSourceNat = sharedSourceNat;
+    }
+
+    @Override
+    public boolean getRedundantRouter() {
+        return redundantRouter;
+    }
+
+    public void setRedundantRouter(boolean redundantRouter) {
+        this.redundantRouter = redundantRouter;
+    }
+
+    public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
+            Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean specifyIpRanges, boolean isPersistent, boolean internalLb, boolean publicLb) {
+        this.name = name;
+        this.displayText = displayText;
+        this.rateMbps = rateMbps;
+        this.multicastRateMbps = multicastRateMbps;
+        this.trafficType = trafficType;
+        this.systemOnly = systemOnly;
+        this.specifyVlan = specifyVlan;
+        this.isDefault = isDefault;
+        this.availability = availability;
+        this.uniqueName = name;
+        this.uuid = UUID.randomUUID().toString();
+        this.tags = tags;
+        this.guestType = guestType;
+        this.conserveMode = conserveMode;
+        this.dedicatedLB = true;
+        this.sharedSourceNat = false;
+        this.redundantRouter = false;
+        this.elasticIp = false;
+        this.eipAssociatePublicIp = true;
+        this.elasticLb = false;
+        this.inline = false;
+        this.specifyIpRanges = specifyIpRanges;
+        this.isPersistent=isPersistent;
+        this.publicLb = publicLb;
+        this.internalLb = internalLb;
+    }
+
+    public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
+            Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb,
+            boolean specifyIpRanges, boolean inline, boolean isPersistent, boolean associatePublicIP, boolean publicLb, boolean internalLb) {
+        this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges, isPersistent, internalLb, publicLb);
+        this.dedicatedLB = dedicatedLb;
+        this.sharedSourceNat = sharedSourceNat;
+        this.redundantRouter = redundantRouter;
+        this.elasticIp = elasticIp;
+        this.elasticLb = elasticLb;
+        this.inline = inline;
+        this.eipAssociatePublicIp = associatePublicIP;
+    }
+
+    public NetworkOfferingVO() {
+    }
+
+    /**
+     * Network Offering for all system vms.
+     *
+     * @param name
+     * @param trafficType
+     * @param specifyIpRanges
+     *            TODO
+     */
+    public NetworkOfferingVO(String name, TrafficType trafficType, boolean specifyIpRanges) {
+        this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges, false, false, false);
+        this.state = State.Enabled;
+    }
+
+    public NetworkOfferingVO(String name, Network.GuestType guestType) {
+        this(name, "System Offering for " + name, TrafficType.Guest, true, true, 0, 0, true, Availability.Optional,
+                null, Network.GuestType.Isolated, true, false, false, false, false);
+        this.state = State.Enabled;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder buf = new StringBuilder("[Network Offering [");
+        return buf.append(id).append("-").append(trafficType).append("-").append(name).append("]").toString();
+    }
+
+    @Override
+    public String getUuid() {
+        return this.uuid;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+    public void setSortKey(int key) {
+        sortKey = key;
+    }
+
+    public int getSortKey() {
+        return sortKey;
+    }
+
+    public void setUniqueName(String uniqueName) {
+        this.uniqueName = uniqueName;
+    }
+
+    @Override
+    public boolean isConserveMode() {
+        return conserveMode;
+    }
+
+    @Override
+    public boolean getElasticIp() {
+        return elasticIp;
+    }
+
+    @Override
+    public boolean getAssociatePublicIP() {
+        return eipAssociatePublicIp;
+    }
+
+    @Override
+    public boolean getElasticLb() {
+        return elasticLb;
+    }
+
+    @Override
+    public boolean getSpecifyIpRanges() {
+        return specifyIpRanges;
+    }
+
+    @Override
+    public boolean isInline() {
+        return inline;
+    }
+
+    public void setIsPersistent(Boolean isPersistent) {
+        this.isPersistent = isPersistent;
+    }
+
+    public boolean getIsPersistent() {
+        return isPersistent;
+    }
+
+    @Override
+    public boolean getInternalLb() {
+        return internalLb;
+    }
+
+    @Override
+    public boolean getPublicLb() {
+        return publicLb;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java
new file mode 100644
index 0000000..5bb79ce
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java
@@ -0,0 +1,64 @@
+// 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.offerings.dao;
+
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.network.Network;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.NetworkOffering.Availability;
+import com.cloud.offering.NetworkOffering.Detail;
+import com.cloud.offerings.NetworkOfferingVO;
+import com.cloud.utils.db.GenericDao;
+
+/**
+ * NetworkOfferingDao deals with searches and operations done on the
+ * network_offering table.
+ * 
+ */
+public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long> {
+    /**
+     * Returns the network offering that matches the name.
+     * 
+     * @param uniqueName
+     *            name
+     * @return NetworkOfferingVO
+     */
+    NetworkOfferingVO findByUniqueName(String uniqueName);
+
+    /**
+     * If not, then it persists it into the database.
+     * 
+     * @param offering
+     *            network offering to persist if not in the database.
+     * @return NetworkOfferingVO backed by a row in the database
+     */
+    NetworkOfferingVO persistDefaultNetworkOffering(NetworkOfferingVO offering);
+
+    List<NetworkOfferingVO> listSystemNetworkOfferings();
+
+    List<NetworkOfferingVO> listByAvailability(Availability availability, boolean isSystem);
+
+    List<Long> getOfferingIdsToUpgradeFrom(NetworkOffering originalOffering);
+
+    List<NetworkOfferingVO> listByTrafficTypeGuestTypeAndState(NetworkOffering.State state, TrafficType trafficType, Network.GuestType type);
+
+    NetworkOfferingVO persist(NetworkOfferingVO off, Map<Detail, String> details);
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java
new file mode 100644
index 0000000..ef8237a
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java
@@ -0,0 +1,193 @@
+// 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.offerings.dao;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.persistence.EntityExistsException;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.Network;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.NetworkOffering.Availability;
+import com.cloud.offering.NetworkOffering.Detail;
+import com.cloud.offerings.NetworkOfferingDetailsVO;
+import com.cloud.offerings.NetworkOfferingVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = NetworkOfferingDao.class)
+@DB(txn = false)
+public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Long> implements NetworkOfferingDao {
+    final SearchBuilder<NetworkOfferingVO> NameSearch;
+    final SearchBuilder<NetworkOfferingVO> SystemOfferingSearch;
+    final SearchBuilder<NetworkOfferingVO> AvailabilitySearch;
+    final SearchBuilder<NetworkOfferingVO> AllFieldsSearch;
+    private final GenericSearchBuilder<NetworkOfferingVO, Long> UpgradeSearch;
+    @Inject NetworkOfferingDetailsDao _detailsDao;
+
+    protected NetworkOfferingDaoImpl() {
+        super();
+
+        NameSearch = createSearchBuilder();
+        NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
+        NameSearch.and("uniqueName", NameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
+        NameSearch.done();
+
+        SystemOfferingSearch = createSearchBuilder();
+        SystemOfferingSearch.and("system", SystemOfferingSearch.entity().isSystemOnly(), SearchCriteria.Op.EQ);
+        SystemOfferingSearch.done();
+
+        AvailabilitySearch = createSearchBuilder();
+        AvailabilitySearch.and("availability", AvailabilitySearch.entity().getAvailability(), SearchCriteria.Op.EQ);
+        AvailabilitySearch.and("isSystem", AvailabilitySearch.entity().isSystemOnly(), SearchCriteria.Op.EQ);
+        AvailabilitySearch.done();
+
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("trafficType", AllFieldsSearch.entity().getTrafficType(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("guestType", AllFieldsSearch.entity().getGuestType(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("isSystem", AllFieldsSearch.entity().isSystemOnly(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.done();
+
+        UpgradeSearch = createSearchBuilder(Long.class);
+        UpgradeSearch.selectField(UpgradeSearch.entity().getId());
+        UpgradeSearch.and("physicalNetworkId", UpgradeSearch.entity().getId(), Op.NEQ);
+        UpgradeSearch.and("physicalNetworkId", UpgradeSearch.entity().isSystemOnly(), Op.EQ);
+        UpgradeSearch.and("trafficType", UpgradeSearch.entity().getTrafficType(), Op.EQ);
+        UpgradeSearch.and("guestType", UpgradeSearch.entity().getGuestType(), Op.EQ);
+        UpgradeSearch.and("state", UpgradeSearch.entity().getState(), Op.EQ);
+        UpgradeSearch.done();
+    }
+
+    @Override
+    public NetworkOfferingVO findByUniqueName(String uniqueName) {
+        SearchCriteria<NetworkOfferingVO> sc = NameSearch.create();
+
+        sc.setParameters("uniqueName", uniqueName);
+
+        return findOneBy(sc);
+
+    }
+
+    @Override
+    public NetworkOfferingVO persistDefaultNetworkOffering(NetworkOfferingVO offering) {
+        assert offering.getUniqueName() != null : "how are you going to find this later if you don't set it?";
+        NetworkOfferingVO vo = findByUniqueName(offering.getUniqueName());
+        if (vo != null) {
+            return vo;
+        }
+        try {
+            vo = persist(offering);
+            return vo;
+        } catch (EntityExistsException e) {
+            // Assume it's conflict on unique name from two different management servers.
+            return findByUniqueName(offering.getName());
+        }
+    }
+
+    @Override
+    public List<NetworkOfferingVO> listSystemNetworkOfferings() {
+        SearchCriteria<NetworkOfferingVO> sc = SystemOfferingSearch.create();
+        sc.setParameters("system", true);
+        return this.listIncludingRemovedBy(sc, null);
+    }
+
+    @Override
+    public List<NetworkOfferingVO> listByAvailability(Availability availability, boolean isSystem) {
+        SearchCriteria<NetworkOfferingVO> sc = AvailabilitySearch.create();
+        sc.setParameters("availability", availability);
+        sc.setParameters("isSystem", isSystem);
+        return listBy(sc, null);
+    }
+
+    @Override
+    @DB
+    public boolean remove(Long networkOfferingId) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        NetworkOfferingVO offering = findById(networkOfferingId);
+        offering.setUniqueName(null);
+        update(networkOfferingId, offering);
+        boolean result = super.remove(networkOfferingId);
+        txn.commit();
+        return result;
+    }
+
+    @Override
+    public List<Long> getOfferingIdsToUpgradeFrom(NetworkOffering originalOffering) {
+        SearchCriteria<Long> sc = UpgradeSearch.create();
+        // exclude original offering
+        sc.addAnd("id", SearchCriteria.Op.NEQ, originalOffering.getId());
+
+        // list only non-system offerings
+        sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false);
+
+        // Type of the network should be the same
+        sc.addAnd("guestType", SearchCriteria.Op.EQ, originalOffering.getGuestType());
+
+        // Traffic types should be the same
+        sc.addAnd("trafficType", SearchCriteria.Op.EQ, originalOffering.getTrafficType());
+
+        sc.addAnd("state", SearchCriteria.Op.EQ, NetworkOffering.State.Enabled);
+        
+        //specify Vlan should be the same
+        sc.addAnd("specifyVlan", SearchCriteria.Op.EQ, originalOffering.getSpecifyVlan());
+
+        return customSearch(sc, null);
+    }
+
+    @Override
+    public List<NetworkOfferingVO> listByTrafficTypeGuestTypeAndState(NetworkOffering.State state, TrafficType trafficType, Network.GuestType type) {
+        SearchCriteria<NetworkOfferingVO> sc = AllFieldsSearch.create();
+        sc.setParameters("trafficType", trafficType);
+        sc.setParameters("guestType", type);
+        sc.setParameters("state", state);
+        return listBy(sc, null);
+    }
+    
+    @Override
+    @DB
+    public NetworkOfferingVO persist(NetworkOfferingVO off, Map<Detail, String> details) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        //1) persist the offering
+        NetworkOfferingVO vo = super.persist(off);
+        
+        //2) persist the details
+        if (details != null && !details.isEmpty()) {
+            for (NetworkOffering.Detail detail : details.keySet()) {
+                _detailsDao.persist(new NetworkOfferingDetailsVO(off.getId(), detail, details.get(detail)));
+            }
+        }
+       
+        txn.commit();
+        return vo;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDetailsDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDetailsDao.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDetailsDao.java
new file mode 100644
index 0000000..ce209e0
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDetailsDao.java
@@ -0,0 +1,31 @@
+// 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.offerings.dao;
+
+
+import java.util.Map;
+
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.NetworkOffering.Detail;
+import com.cloud.offerings.NetworkOfferingDetailsVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface NetworkOfferingDetailsDao extends GenericDao<NetworkOfferingDetailsVO, Long>{
+
+    Map<NetworkOffering.Detail,String> getNtwkOffDetails(long offeringId);
+    String getDetail(long offeringId, Detail detailName);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDetailsDaoImpl.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDetailsDaoImpl.java
new file mode 100644
index 0000000..068f390
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDetailsDaoImpl.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.offerings.dao;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.NetworkOffering.Detail;
+import com.cloud.offerings.NetworkOfferingDetailsVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+public class NetworkOfferingDetailsDaoImpl extends GenericDaoBase<NetworkOfferingDetailsVO, Long> implements NetworkOfferingDetailsDao{
+    protected final SearchBuilder<NetworkOfferingDetailsVO> DetailSearch;
+    private final GenericSearchBuilder<NetworkOfferingDetailsVO, String> ValueSearch;
+
+    
+    public NetworkOfferingDetailsDaoImpl() {
+        
+        DetailSearch = createSearchBuilder();
+        DetailSearch.and("offeringId", DetailSearch.entity().getOfferingId(), SearchCriteria.Op.EQ);
+        DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
+        DetailSearch.done();
+        
+        ValueSearch = createSearchBuilder(String.class);
+        ValueSearch.select(null, Func.DISTINCT, ValueSearch.entity().getValue());
+        ValueSearch.and("offeringId", ValueSearch.entity().getOfferingId(), SearchCriteria.Op.EQ);
+        ValueSearch.and("name", ValueSearch.entity().getName(), Op.EQ);
+        ValueSearch.done();
+    }
+    
+    @Override
+    public Map<NetworkOffering.Detail,String> getNtwkOffDetails(long offeringId) {
+        SearchCriteria<NetworkOfferingDetailsVO> sc = DetailSearch.create();
+        sc.setParameters("offeringId", offeringId);
+        
+        List<NetworkOfferingDetailsVO> results = search(sc, null);
+        Map<NetworkOffering.Detail, String> details = new HashMap<NetworkOffering.Detail, String>(results.size());
+        for (NetworkOfferingDetailsVO result : results) {
+            details.put(result.getName(), result.getValue());
+        }
+        
+        return details;
+    }
+
+    @Override
+    public String getDetail(long offeringId, Detail detailName) {
+        SearchCriteria<String> sc = ValueSearch.create();
+        sc.setParameters("name", detailName);
+        sc.setParameters("offeringId", offeringId);
+        List<String> results = customSearch(sc, null);
+        if (results.isEmpty()) {
+            return null;
+        } else {
+            return results.get(0);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java
new file mode 100644
index 0000000..42ab0eb
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java
@@ -0,0 +1,50 @@
+// 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.offerings.dao;
+
+import java.util.List;
+
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.offerings.NetworkOfferingServiceMapVO;
+import com.cloud.utils.db.GenericDao;
+
+/**
+ * NetworkOfferingServiceDao deals with searches and operations done on the
+ * ntwk_offering_service_map table.
+ *
+ */
+public interface NetworkOfferingServiceMapDao extends GenericDao<NetworkOfferingServiceMapVO, Long> {
+   boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
+   
+   List<NetworkOfferingServiceMapVO> listByNetworkOfferingId(long networkOfferingId);
+   
+   void deleteByOfferingId(long networkOfferingId);
+   
+   List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service);
+   
+   boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider);
+   
+   List<String> listServicesForNetworkOffering(long networkOfferingId);
+   
+   List<String> getDistinctProviders(long offId);
+}
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java
new file mode 100644
index 0000000..7282443
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java
@@ -0,0 +1,171 @@
+// 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.offerings.dao;
+
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.offerings.NetworkOfferingServiceMapVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+
+@Component
+@Local(value=NetworkOfferingServiceMapDao.class) @DB(txn=false)
+public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOfferingServiceMapVO, Long> implements NetworkOfferingServiceMapDao {
+
+	final SearchBuilder<NetworkOfferingServiceMapVO> AllFieldsSearch;
+    final SearchBuilder<NetworkOfferingServiceMapVO> MultipleServicesSearch;
+    final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> ProvidersSearch;
+    final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> ServicesSearch;
+    final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> DistinctProvidersSearch;
+
+    
+    protected NetworkOfferingServiceMapDaoImpl() {
+        super();
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("networkOfferingId", AllFieldsSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("service", AllFieldsSearch.entity().getService(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("provider", AllFieldsSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.done();
+        
+        MultipleServicesSearch = createSearchBuilder();
+        MultipleServicesSearch.and("networkOfferingId", MultipleServicesSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+        MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
+        MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+        MultipleServicesSearch.done();
+        
+        ProvidersSearch = createSearchBuilder(String.class);
+        ProvidersSearch.and("networkOfferingId", ProvidersSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+        ProvidersSearch.and("service", ProvidersSearch.entity().getService(), SearchCriteria.Op.EQ);
+        ProvidersSearch.select(null, Func.DISTINCT, ProvidersSearch.entity().getProvider());
+        ProvidersSearch.done();
+        
+        ServicesSearch = createSearchBuilder(String.class);
+        ServicesSearch.and("networkOfferingId", ServicesSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+        ServicesSearch.select(null, Func.DISTINCT, ServicesSearch.entity().getService());
+        ServicesSearch.done();
+        
+        DistinctProvidersSearch = createSearchBuilder(String.class);
+        DistinctProvidersSearch.and("offId", DistinctProvidersSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+        DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+        DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
+        DistinctProvidersSearch.done();
+    }
+    
+    @Override
+    public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) {
+        SearchCriteria<NetworkOfferingServiceMapVO> sc = MultipleServicesSearch.create();
+        sc.setParameters("networkOfferingId", networkOfferingId);
+        
+        if (services != null) {
+            String[] servicesStr = new String[services.length];
+            
+            int i = 0;
+            for (Service service : services) {
+                servicesStr[i] = service.getName();
+                i++;
+            }
+            
+            sc.setParameters("service", (Object[])servicesStr);
+        }
+        
+        List<NetworkOfferingServiceMapVO> offeringServices = listBy(sc);
+        
+        if (services != null) {
+            if (offeringServices.size() == services.length) {
+                return true;
+            }
+        } else if (!offeringServices.isEmpty()) {
+            return true;
+        }
+        
+        return false;
+    }
+ 
+    @Override
+    public List<NetworkOfferingServiceMapVO> listByNetworkOfferingId(long networkOfferingId) {
+        SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkOfferingId", networkOfferingId);
+        return listBy(sc);
+    }
+    
+    @Override
+    public void deleteByOfferingId(long networkOfferingId) {
+        SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkOfferingId", networkOfferingId);
+        remove(sc);
+    }
+    
+    @Override
+    public List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service) {
+    	SearchCriteria<String> sc = ProvidersSearch.create();;
+    	
+        sc.setParameters("networkOfferingId", networkOfferingId);
+        sc.setParameters("service", service.getName());
+        
+        return customSearch(sc, null);
+    }
+
+    @Override
+    public boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider) {
+    	SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();;
+    	
+        sc.setParameters("networkOfferingId", networkOfferingId);
+        sc.setParameters("provider", provider.getName());
+        
+        if (findOneBy(sc) != null) {
+            return true;
+        }
+        return false;
+    }
+    
+    @Override
+    public List<String> listServicesForNetworkOffering(long networkOfferingId) {
+    	SearchCriteria<String> sc = ServicesSearch.create();;
+        sc.setParameters("networkOfferingId", networkOfferingId);
+        return customSearch(sc, null);
+    }
+    
+    @Override
+	public NetworkOfferingServiceMapVO persist(
+			NetworkOfferingServiceMapVO entity) {
+        SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkOfferingId", entity.getNetworkOfferingId());
+        sc.setParameters("service", entity.getService());
+        sc.setParameters("provider", entity.getProvider());
+        NetworkOfferingServiceMapVO mappingInDb = findOneBy(sc);
+        return mappingInDb!=null? mappingInDb : super.persist(entity); 
+	}
+    
+    @Override
+    public List<String> getDistinctProviders(long offId) {
+        SearchCriteria<String> sc = DistinctProvidersSearch.create();
+        sc.setParameters("offId", offId);
+        List<String> results = customSearch(sc, null);
+        return results;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/ProjectAccountVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/ProjectAccountVO.java b/engine/schema/src/com/cloud/projects/ProjectAccountVO.java
new file mode 100644
index 0000000..8c4f1ba
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/ProjectAccountVO.java
@@ -0,0 +1,96 @@
+// 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.projects;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="project_account")
+@SuppressWarnings("unused")
+public class ProjectAccountVO implements ProjectAccount, InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+    
+    @Column(name="project_id")
+    private long projectId;
+
+    @Column(name="account_id")
+    private long accountId;
+    
+    @Column(name="account_role")
+    @Enumerated(value=EnumType.STRING)
+    private Role accountRole = Role.Regular;
+    
+    @Column(name="project_account_id")
+    long projectAccountId;
+    
+    @Column(name=GenericDao.CREATED_COLUMN)
+    private Date created;
+
+    
+    protected ProjectAccountVO(){
+    }
+    
+    public ProjectAccountVO(Project project, long accountId, Role accountRole) {
+       this.accountId = accountId;
+       this.accountRole = accountRole;
+       this.projectId = project.getId();
+       this.projectAccountId = project.getProjectAccountId();
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public long getProjectId() {
+        return projectId;
+    }
+
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+
+    @Override
+    public Role getAccountRole() {
+        return accountRole;
+    }
+    
+    @Override
+    public long getProjectAccountId() {
+        return projectAccountId;
+    }
+
+    public void setAccountRole(Role accountRole) {
+        this.accountRole = accountRole;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java b/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java
new file mode 100644
index 0000000..78f05c7
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java
@@ -0,0 +1,150 @@
+// 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.projects;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.Identity;
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name = "project_invitations")
+public class ProjectInvitationVO implements ProjectInvitation {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "project_id")
+    private long projectId;
+
+    @Column(name = "account_id")
+    private Long forAccountId;
+
+    @Column(name = "domain_id")
+    private Long inDomainId;
+
+    @Column(name = "token")
+    private String token;
+
+    @Column(name = "email")
+    private String email;
+
+    @Column(name = "state")
+    @Enumerated(value = EnumType.STRING)
+    private State state = State.Pending;
+
+    @Column(name = GenericDao.CREATED_COLUMN)
+    private Date created;
+
+    @Column(name = "uuid")
+    private String uuid;
+
+    protected ProjectInvitationVO() {
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public ProjectInvitationVO(long projectId, Long accountId, Long domainId, String email, String token) {
+        this.forAccountId = accountId;
+        this.inDomainId = domainId;
+        this.projectId = projectId;
+        this.email = email;
+        this.token = token;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public long getProjectId() {
+        return projectId;
+    }
+
+    @Override
+    public Long getForAccountId() {
+        return forAccountId;
+    }
+
+    @Override
+    public String getToken() {
+        return token;
+    }
+
+    @Override
+    public String getEmail() {
+        return email;
+    }
+
+    @Override
+    public Date getCreated() {
+        return created;
+    }
+
+    @Override
+    public State getState() {
+        return state;
+    }
+
+    public void setState(State state) {
+        this.state = state;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder buf = new StringBuilder("ProjectInvitation[");
+        buf.append(id).append("|projectId=").append(projectId).append("|accountId=").append(forAccountId).append("]");
+        return buf.toString();
+    }
+
+    @Override
+    public Long getInDomainId() {
+        return inDomainId;
+    }
+
+    @Override
+    public String getUuid() {
+        return this.uuid;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+    @Override
+    public long getDomainId() {
+        return inDomainId == null ? -1 : inDomainId;
+    }
+
+    @Override
+    public long getAccountId() {
+        return forAccountId == null ? -1 : forAccountId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/ProjectVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/ProjectVO.java b/engine/schema/src/com/cloud/projects/ProjectVO.java
new file mode 100644
index 0000000..53947f1
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/ProjectVO.java
@@ -0,0 +1,163 @@
+// 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.projects;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.Identity;
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="projects")
+public class ProjectVO implements Project, Identity, InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+    
+    @Column(name="name")
+    private String name;
+    
+    @Column(name="display_text")
+    String displayText;
+    
+    @Column(name="domain_id")
+    long domainId;
+
+    @Column(name="project_account_id")
+    long projectAccountId;
+    
+    @Column(name="state")
+    @Enumerated(value=EnumType.STRING)
+    private State state;
+    
+    @Column(name=GenericDao.CREATED_COLUMN)
+    private Date created;
+    
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    private Date removed;
+    
+    @Column(name="uuid")
+    private String uuid;
+    
+    protected ProjectVO(){
+    	this.uuid = UUID.randomUUID().toString();
+    }
+    
+    public ProjectVO(String name, String displayText, long domainId, long projectAccountId) {
+        this.name = name;
+        this.displayText = displayText;
+        this.projectAccountId = projectAccountId;
+        this.domainId = domainId;
+        this.state = State.Disabled;
+    	this.uuid = UUID.randomUUID().toString();
+    }
+    
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getDisplayText() {
+        return displayText;
+    }
+
+    public void setDisplayText(String displayText) {
+        this.displayText = displayText;
+    }
+
+    @Override
+    public long getDomainId() {
+        return domainId;
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public Date getCreated() {
+        return created;
+    }
+
+    @Override
+    public Date getRemoved() {
+        return removed;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder buf = new StringBuilder("Project[");
+        buf.append(id).append("|name=").append(name).append("|domainid=").append(domainId).append("]");
+        return buf.toString();
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof ProjectVO)) {
+            return false;
+        }
+        ProjectVO that = (ProjectVO)obj;
+        if (this.id != that.id) {
+            return false;
+        }
+        
+        return true;
+    }
+
+    @Override
+    public long getProjectAccountId() {
+        return projectAccountId;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public State getState() {
+        return state;
+    }
+
+    @Override
+    public void setState(State state) {
+        this.state = state;
+    }
+    
+    @Override
+    public String getUuid() {
+    	return this.uuid; 
+    }
+    
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/dao/ProjectAccountDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/dao/ProjectAccountDao.java b/engine/schema/src/com/cloud/projects/dao/ProjectAccountDao.java
new file mode 100644
index 0000000..4ff59be
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/dao/ProjectAccountDao.java
@@ -0,0 +1,43 @@
+// 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.projects.dao;
+
+import java.util.List;
+
+import com.cloud.projects.ProjectAccount;
+import com.cloud.projects.ProjectAccountVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {
+    ProjectAccountVO getProjectOwner(long projectId);
+
+    List<ProjectAccountVO> listByProjectId(long projectId);
+
+    ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId);
+
+    boolean canAccessProjectAccount(long accountId, long projectAccountId);
+
+    boolean canModifyProjectAccount(long accountId, long projectAccountId);
+
+    List<Long> listPermittedAccountIds(long accountId);
+
+    List<Long> listAdministratedProjectIds(long adminAccountId);
+
+    Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role);
+    
+    void removeAccountFromProjects(long accountId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/dao/ProjectAccountDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/dao/ProjectAccountDaoImpl.java b/engine/schema/src/com/cloud/projects/dao/ProjectAccountDaoImpl.java
new file mode 100644
index 0000000..b089e58
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/dao/ProjectAccountDaoImpl.java
@@ -0,0 +1,157 @@
+// 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.projects.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.projects.ProjectAccount;
+import com.cloud.projects.ProjectAccountVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value = { ProjectAccountDao.class })
+public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long> implements ProjectAccountDao {
+    protected final SearchBuilder<ProjectAccountVO> AllFieldsSearch;
+    final GenericSearchBuilder<ProjectAccountVO, Long> AdminSearch;
+    final GenericSearchBuilder<ProjectAccountVO, Long> ProjectAccountSearch;
+    final GenericSearchBuilder<ProjectAccountVO, Long> CountByRoleSearch;
+    public static final Logger s_logger = Logger.getLogger(ProjectAccountDaoImpl.class.getName());
+
+    protected ProjectAccountDaoImpl() {
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("role", AllFieldsSearch.entity().getAccountRole(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("projectId", AllFieldsSearch.entity().getProjectId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("projectAccountId", AllFieldsSearch.entity().getProjectAccountId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.done();
+
+        AdminSearch = createSearchBuilder(Long.class);
+        AdminSearch.selectField(AdminSearch.entity().getProjectId());
+        AdminSearch.and("role", AdminSearch.entity().getAccountRole(), Op.EQ);
+        AdminSearch.and("accountId", AdminSearch.entity().getAccountId(), Op.EQ);
+        AdminSearch.done();
+
+        ProjectAccountSearch = createSearchBuilder(Long.class);
+        ProjectAccountSearch.selectField(ProjectAccountSearch.entity().getProjectAccountId());
+        ProjectAccountSearch.and("accountId", ProjectAccountSearch.entity().getAccountId(), Op.EQ);
+        ProjectAccountSearch.done();
+
+        CountByRoleSearch = createSearchBuilder(Long.class);
+        CountByRoleSearch.select(null, Func.COUNT, CountByRoleSearch.entity().getId());
+        CountByRoleSearch.and("accountId", CountByRoleSearch.entity().getAccountId(), Op.EQ);
+        CountByRoleSearch.and("role", CountByRoleSearch.entity().getAccountRole(), Op.EQ);
+        CountByRoleSearch.done();
+    }
+
+    @Override
+    public ProjectAccountVO getProjectOwner(long projectId) {
+        SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
+        sc.setParameters("role", ProjectAccount.Role.Admin);
+        sc.setParameters("projectId", projectId);
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<ProjectAccountVO> listByProjectId(long projectId) {
+        SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
+        sc.setParameters("projectId", projectId);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId) {
+        SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
+        sc.setParameters("projectId", projectId);
+        sc.setParameters("accountId", accountId);
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public boolean canAccessProjectAccount(long accountId, long projectAccountId) {
+        SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
+        sc.setParameters("accountId", accountId);
+        sc.setParameters("projectAccountId", projectAccountId);
+
+        if (findOneBy(sc) != null) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public boolean canModifyProjectAccount(long accountId, long projectAccountId) {
+        SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
+        sc.setParameters("accountId", accountId);
+        sc.setParameters("projectAccountId", projectAccountId);
+        sc.setParameters("role", ProjectAccount.Role.Admin);
+
+        if (findOneBy(sc) != null) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public List<Long> listPermittedAccountIds(long accountId) {
+        SearchCriteria<Long> sc = ProjectAccountSearch.create();
+        sc.setParameters("accountId", accountId);
+        return customSearch(sc, null);
+    }
+
+    @Override
+    public List<Long> listAdministratedProjectIds(long adminAccountId) {
+        SearchCriteria<Long> sc = AdminSearch.create();
+        sc.setParameters("role", ProjectAccount.Role.Admin);
+        sc.setParameters("accountId", adminAccountId);
+        return customSearch(sc, null);
+    }
+
+    @Override
+    public Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role) {
+        SearchCriteria<Long> sc = CountByRoleSearch.create();
+        sc.setParameters("accountId", accountId);
+        sc.setParameters("role", role);
+        return customSearch(sc, null).get(0);
+    }
+    
+    @Override
+    public void removeAccountFromProjects(long accountId) {
+        SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
+        sc.setParameters("accountId", accountId);
+
+        int rowsRemoved = remove(sc);
+        if (rowsRemoved > 0) {
+            s_logger.debug("Removed account id=" + accountId + " from " + rowsRemoved + " projects");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/dao/ProjectDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/dao/ProjectDao.java b/engine/schema/src/com/cloud/projects/dao/ProjectDao.java
new file mode 100644
index 0000000..e741f24
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/dao/ProjectDao.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.projects.dao;
+
+import java.util.List;
+
+import com.cloud.projects.Project;
+import com.cloud.projects.ProjectVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface ProjectDao extends GenericDao<ProjectVO, Long> {
+
+    ProjectVO findByNameAndDomain(String name, long domainId);
+
+    Long countProjectsForDomain(long domainId);
+
+    ProjectVO findByProjectAccountId(long projectAccountId);
+
+    List<ProjectVO> listByState(Project.State state);
+    
+    ProjectVO findByProjectAccountIdIncludingRemoved(long projectAccountId);
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/dao/ProjectDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/dao/ProjectDaoImpl.java b/engine/schema/src/com/cloud/projects/dao/ProjectDaoImpl.java
new file mode 100644
index 0000000..ecf40da
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/dao/ProjectDaoImpl.java
@@ -0,0 +1,124 @@
+// 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.projects.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.projects.Project;
+import com.cloud.projects.ProjectVO;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
+
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = { ProjectDao.class })
+public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements ProjectDao {
+    private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class);
+    protected final SearchBuilder<ProjectVO> AllFieldsSearch;
+    protected GenericSearchBuilder<ProjectVO, Long> CountByDomain;
+    protected GenericSearchBuilder<ProjectVO, Long> ProjectAccountSearch;
+    // ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
+    @Inject ResourceTagDao _tagsDao;
+
+    protected ProjectDaoImpl() {
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("domainId", AllFieldsSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("projectAccountId", AllFieldsSearch.entity().getProjectAccountId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.done();
+
+        CountByDomain = createSearchBuilder(Long.class);
+        CountByDomain.select(null, Func.COUNT, null);
+        CountByDomain.and("domainId", CountByDomain.entity().getDomainId(), SearchCriteria.Op.EQ);
+        CountByDomain.done();
+    }
+
+    @Override
+    public ProjectVO findByNameAndDomain(String name, long domainId) {
+        SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
+        sc.setParameters("name", name);
+        sc.setParameters("domainId", domainId);
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    @DB
+    public boolean remove(Long projectId) {
+        boolean result = false;
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        ProjectVO projectToRemove = findById(projectId);
+        projectToRemove.setName(null);
+        if (!update(projectId, projectToRemove)) {
+            s_logger.warn("Failed to reset name for the project id=" + projectId + " as a part of project remove");
+            return false;
+        } 
+        
+        _tagsDao.removeByIdAndType(projectId, TaggedResourceType.Project);
+        result = super.remove(projectId);
+        txn.commit();
+
+        return result;
+
+    }
+
+    @Override
+    public Long countProjectsForDomain(long domainId) {
+        SearchCriteria<Long> sc = CountByDomain.create();
+        sc.setParameters("domainId", domainId);
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public ProjectVO findByProjectAccountId(long projectAccountId) {
+        SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
+        sc.setParameters("projectAccountId", projectAccountId);
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<ProjectVO> listByState(Project.State state) {
+        SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
+        sc.setParameters("state", state);
+        return listBy(sc);
+    }
+    
+    @Override
+    public ProjectVO findByProjectAccountIdIncludingRemoved(long projectAccountId) {
+        SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
+        sc.setParameters("projectAccountId", projectAccountId);
+
+        return findOneIncludingRemovedBy(sc);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/dao/ProjectInvitationDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/dao/ProjectInvitationDao.java b/engine/schema/src/com/cloud/projects/dao/ProjectInvitationDao.java
new file mode 100644
index 0000000..3788641
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/dao/ProjectInvitationDao.java
@@ -0,0 +1,44 @@
+// 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.projects.dao;
+
+import java.util.List;
+
+import com.cloud.projects.ProjectInvitation.State;
+import com.cloud.projects.ProjectInvitationVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface ProjectInvitationDao extends GenericDao<ProjectInvitationVO, Long> {
+    ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState);
+
+    List<ProjectInvitationVO> listExpiredInvitations();
+
+    boolean expirePendingInvitations(long timeOut);
+
+    boolean isActive(long id, long timeout);
+
+    ProjectInvitationVO findByEmailAndProjectId(String email, long projectId, State... inviteState);
+
+    ProjectInvitationVO findPendingByTokenAndProjectId(String token, long projectId, State... inviteState);
+
+    void cleanupInvitations(long projectId);
+
+    ProjectInvitationVO findPendingById(long id);
+
+    List<ProjectInvitationVO> listInvitationsToExpire(long timeOut);
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/projects/dao/ProjectInvitationDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/dao/ProjectInvitationDaoImpl.java b/engine/schema/src/com/cloud/projects/dao/ProjectInvitationDaoImpl.java
new file mode 100644
index 0000000..4491512
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/dao/ProjectInvitationDaoImpl.java
@@ -0,0 +1,171 @@
+// 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.projects.dao;
+
+import java.sql.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.projects.ProjectInvitation.State;
+import com.cloud.projects.ProjectInvitationVO;
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value = { ProjectInvitationDao.class })
+public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO, Long> implements ProjectInvitationDao {
+    private static final Logger s_logger = Logger.getLogger(ProjectInvitationDaoImpl.class);
+    protected final SearchBuilder<ProjectInvitationVO> AllFieldsSearch;
+    protected final SearchBuilder<ProjectInvitationVO> InactiveSearch;
+
+    protected ProjectInvitationDaoImpl() {
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getForAccountId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("projectId", AllFieldsSearch.entity().getProjectId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("created", AllFieldsSearch.entity().getCreated(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("projectAccountId", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.IN);
+        AllFieldsSearch.and("email", AllFieldsSearch.entity().getEmail(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("token", AllFieldsSearch.entity().getToken(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.done();
+
+        InactiveSearch = createSearchBuilder();
+        InactiveSearch.and("id", InactiveSearch.entity().getId(), SearchCriteria.Op.EQ);
+        InactiveSearch.and("accountId", InactiveSearch.entity().getForAccountId(), SearchCriteria.Op.EQ);
+        InactiveSearch.and("projectId", InactiveSearch.entity().getProjectId(), SearchCriteria.Op.EQ);
+        InactiveSearch.and("created", InactiveSearch.entity().getCreated(), SearchCriteria.Op.LTEQ);
+        InactiveSearch.and("state", InactiveSearch.entity().getState(), SearchCriteria.Op.EQ);
+        InactiveSearch.done();
+    }
+
+    @Override
+    public ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState) {
+        SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
+        sc.setParameters("accountId", accountId);
+        sc.setParameters("projectId", projectId);
+        if (inviteState != null && inviteState.length > 0) {
+            sc.setParameters("state", (Object[]) inviteState);
+        }
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<ProjectInvitationVO> listExpiredInvitations() {
+        SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
+        sc.setParameters("state", State.Expired);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public boolean expirePendingInvitations(long timeout) {
+        boolean success = true;
+
+        SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
+        sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime() >> 10) - timeout));
+        sc.setParameters("state", State.Pending);
+
+        List<ProjectInvitationVO> invitationsToExpire = listBy(sc);
+        for (ProjectInvitationVO invitationToExpire : invitationsToExpire) {
+            invitationToExpire.setState(State.Expired);
+            if (!update(invitationToExpire.getId(), invitationToExpire)) {
+                s_logger.warn("Fail to expire invitation " + invitationToExpire.toString());
+                success = false;
+            }
+        }
+        return success;
+    }
+
+    @Override
+    public List<ProjectInvitationVO> listInvitationsToExpire(long timeOut) {
+        SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
+        sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - timeOut));
+        sc.setParameters("state", State.Pending);
+        return listBy(sc);
+    }
+
+    @Override
+    public boolean isActive(long id, long timeout) {
+        SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
+
+        sc.setParameters("id", id);
+
+        if (findOneBy(sc) == null) {
+            s_logger.warn("Unable to find project invitation by id " + id);
+            return false;
+        }
+
+        sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - timeout));
+
+        if (findOneBy(sc) == null) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public ProjectInvitationVO findByEmailAndProjectId(String email, long projectId, State... inviteState) {
+        SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
+        sc.setParameters("email", email);
+        sc.setParameters("projectId", projectId);
+        if (inviteState != null && inviteState.length > 0) {
+            sc.setParameters("state", (Object[]) inviteState);
+        }
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public ProjectInvitationVO findPendingByTokenAndProjectId(String token, long projectId, State... inviteState) {
+        SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
+        sc.setParameters("token", token);
+        sc.setParameters("projectId", projectId);
+        if (inviteState != null && inviteState.length > 0) {
+            sc.setParameters("state", (Object[]) inviteState);
+        }
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public ProjectInvitationVO findPendingById(long id) {
+        SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
+        sc.setParameters("id", id);
+        sc.setParameters("state", State.Pending);
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public void cleanupInvitations(long projectId) {
+        SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
+        sc.setParameters("projectId", projectId);
+
+        int numberRemoved = remove(sc);
+        s_logger.debug("Removed " + numberRemoved + " invitations for project id=" + projectId);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/secstorage/CommandExecLogDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/secstorage/CommandExecLogDao.java b/engine/schema/src/com/cloud/secstorage/CommandExecLogDao.java
new file mode 100644
index 0000000..9a7bb6c
--- /dev/null
+++ b/engine/schema/src/com/cloud/secstorage/CommandExecLogDao.java
@@ -0,0 +1,25 @@
+// 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.secstorage;
+
+import java.util.Date;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface CommandExecLogDao extends GenericDao<CommandExecLogVO, Long> {
+	public void expungeExpiredRecords(Date cutTime);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/secstorage/CommandExecLogDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/secstorage/CommandExecLogDaoImpl.java b/engine/schema/src/com/cloud/secstorage/CommandExecLogDaoImpl.java
new file mode 100644
index 0000000..8fa9e41
--- /dev/null
+++ b/engine/schema/src/com/cloud/secstorage/CommandExecLogDaoImpl.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.secstorage;
+
+import java.util.Date;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value={CommandExecLogDao.class})
+public class CommandExecLogDaoImpl extends GenericDaoBase<CommandExecLogVO, Long> implements CommandExecLogDao {
+
+    protected final SearchBuilder<CommandExecLogVO> ExpungeSearch;
+	
+	public CommandExecLogDaoImpl() {
+		ExpungeSearch = createSearchBuilder();
+		ExpungeSearch.and("created", ExpungeSearch.entity().getCreated(), Op.LT);
+		ExpungeSearch.done();
+	}
+	
+	@Override
+	public void expungeExpiredRecords(Date cutTime) {
+		SearchCriteria<CommandExecLogVO> sc = ExpungeSearch.create();
+		sc.setParameters("created", cutTime);
+		expunge(sc);
+	}
+}
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/secstorage/CommandExecLogVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/secstorage/CommandExecLogVO.java b/engine/schema/src/com/cloud/secstorage/CommandExecLogVO.java
new file mode 100644
index 0000000..4ec023e
--- /dev/null
+++ b/engine/schema/src/com/cloud/secstorage/CommandExecLogVO.java
@@ -0,0 +1,112 @@
+// 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.secstorage;
+
+import java.util.Date;
+
+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 javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import com.cloud.utils.DateUtil;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="cmd_exec_log")
+public class CommandExecLogVO implements InternalIdentity {
+	
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+	private long id;
+    
+    @Column(name="host_id")
+	private long hostId;
+    
+    @Column(name="instance_id")
+	private long instanceId;
+	
+    @Column(name="command_name")
+	private String commandName;
+    
+    @Column(name="weight")
+    private int weight;
+	
+    @Column(name="created")
+    @Temporal(value=TemporalType.TIMESTAMP)
+    private Date created;
+    
+    public CommandExecLogVO() {
+    }
+    
+    public CommandExecLogVO(long hostId, long instanceId, String commandName, int weight) {
+    	this.hostId = hostId;
+    	this.instanceId = instanceId;
+    	this.commandName = commandName;
+    	this.weight = weight;
+    	this.created = DateUtil.currentGMTTime();
+    }
+    
+    public long getId() {
+    	return this.id;
+    }
+    
+    public long getHostId() {
+    	return this.hostId;
+    }
+    
+    public void setHostId(long hostId) {
+    	this.hostId = hostId;
+    }
+    
+    public long getInstanceId() {
+    	return this.instanceId;
+    }
+    
+    public void setInstanceId(long instanceId) {
+    	this.instanceId = instanceId;
+    }
+    
+    public String getCommandName() {
+    	return this.commandName;
+    }
+    
+    public void setCommandName(String commandName) {
+    	this.commandName = commandName;
+    }
+    
+    public int getWeight() {
+    	return weight;
+    }
+    
+    public void setWeight(int weight) {
+    	this.weight = weight;
+    }
+    
+    public Date getCreated() {
+    	return this.created;
+    }
+    
+    public void setCreated(Date created) {
+    	this.created = created;
+    }
+}


Mime
View raw message