incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [42/50] [abbrv] Sync master to javelin one more time
Date Fri, 01 Feb 2013 23:27:31 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/NetworkServiceImpl.java
index f0282ab,622b448..6872c3f
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@@ -79,20 -47,7 +72,21 @@@ import com.cloud.network.Networks.Traff
  import com.cloud.network.PhysicalNetwork.BroadcastDomainRange;
  import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
  import com.cloud.network.addr.PublicIp;
 +import com.cloud.network.dao.FirewallRulesDao;
 +import com.cloud.network.dao.IPAddressDao;
 +import com.cloud.network.dao.IPAddressVO;
 +import com.cloud.network.dao.NetworkDao;
 +import com.cloud.network.dao.NetworkDomainDao;
 +import com.cloud.network.dao.NetworkDomainVO;
 +import com.cloud.network.dao.NetworkServiceMapDao;
 +import com.cloud.network.dao.NetworkVO;
 +import com.cloud.network.dao.PhysicalNetworkDao;
 +import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
 +import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
 +import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao;
 +import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
 +import com.cloud.network.dao.PhysicalNetworkVO;
+ import com.cloud.network.dao.*;
  import com.cloud.network.element.NetworkElement;
  import com.cloud.network.element.VirtualRouterElement;
  import com.cloud.network.element.VpcVirtualRouterElement;
@@@ -124,27 -73,31 +112,22 @@@ import com.cloud.user.dao.AccountDao
  import com.cloud.utils.AnnotationHelper;
  import com.cloud.utils.NumbersUtil;
  import com.cloud.utils.Pair;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.Inject;
  import com.cloud.utils.component.Manager;
 +import com.cloud.utils.component.ManagerBase;
 +import com.cloud.utils.db.DB;
 +import com.cloud.utils.db.Filter;
 +import com.cloud.utils.db.JoinBuilder;
 +import com.cloud.utils.db.SearchBuilder;
 +import com.cloud.utils.db.SearchCriteria;
+ import com.cloud.utils.db.*;
  import com.cloud.utils.db.SearchCriteria.Op;
- import com.cloud.utils.db.Transaction;
  import com.cloud.utils.exception.CloudRuntimeException;
  import com.cloud.utils.net.NetUtils;
- import com.cloud.vm.NicVO;
- import com.cloud.vm.ReservationContext;
- import com.cloud.vm.ReservationContextImpl;
- import com.cloud.vm.SecondaryStorageVmVO;
- import com.cloud.vm.UserVmVO;
- import com.cloud.vm.VMInstanceVO;
- import com.cloud.vm.VirtualMachine;
+ import com.cloud.vm.*;
  import com.cloud.vm.dao.NicDao;
  import com.cloud.vm.dao.UserVmDao;
  import com.cloud.vm.dao.VMInstanceDao;
 -import org.apache.cloudstack.acl.ControlledEntity.ACLType;
 -import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
 -import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
 -import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
 -import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
 -import org.apache.log4j.Logger;
 -
 -import javax.ejb.Local;
 -import javax.naming.ConfigurationException;
 -import java.security.InvalidParameterException;
 -import java.sql.PreparedStatement;
 -import java.sql.ResultSet;
 -import java.sql.SQLException;
+ import java.util.*;
  
  /**
   * NetworkServiceImpl implements NetworkService.
@@@ -1688,10 -1648,8 +1671,8 @@@ public class NetworkServiceImpl extend
                          continue;
                      }
                      long isDefault = (nic.isDefaultNic()) ? 1 : 0;
-                     UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), null, oldNetworkOfferingId, null, 0L);
-                     _usageEventDao.persist(usageEvent);
-                     usageEvent = new UsageEventVO(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getHostName(), networkOfferingId, null, isDefault);
-                     _usageEventDao.persist(usageEvent);
 -                    UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterIdToDeployIn(), vm.getId(), null, oldNetworkOfferingId, null, 0L);
 -                    UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterIdToDeployIn(), vm.getId(), vm.getHostName(), networkOfferingId, null, isDefault);
++                    UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), null, oldNetworkOfferingId, null, 0L);
++                    UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getHostName(), networkOfferingId, null, isDefault);
                  }
                  txn.commit();
              } else {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/NetworkStateListener.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/NetworkStateListener.java
index 0000000,a379286..bafe6d2
mode 000000,100644..100644
--- a/server/src/com/cloud/network/NetworkStateListener.java
+++ b/server/src/com/cloud/network/NetworkStateListener.java
@@@ -1,0 -1,107 +1,98 @@@
+ // Licensed to the Apache Software Foundation (ASF) under one
+ // or more contributor license agreements.  See the NOTICE file
+ // distributed with this work for additional information
+ // regarding copyright ownership.  The ASF licenses this file
+ // to you under the Apache License, Version 2.0 (the
+ // "License"); you may not use this file except in compliance
+ // with the License.  You may obtain a copy of the License at
+ //
+ //   http://www.apache.org/licenses/LICENSE-2.0
+ //
+ // Unless required by applicable law or agreed to in writing,
+ // software distributed under the License is distributed on an
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ // KIND, either express or implied.  See the License for the
+ // specific language governing permissions and limitations
+ // under the License.
+ 
+ package com.cloud.network;
+ 
+ import com.cloud.event.EventCategory;
+ import com.cloud.event.dao.UsageEventDao;
+ import com.cloud.network.Network.Event;
+ import com.cloud.network.Network.State;
+ import com.cloud.network.dao.NetworkDao;
+ import com.cloud.server.ManagementServer;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.ComponentLocator;
+ import com.cloud.utils.fsm.StateListener;
+ import org.apache.cloudstack.framework.events.EventBus;
+ import org.apache.cloudstack.framework.events.EventBusException;
+ import org.apache.log4j.Logger;
+ 
+ import java.util.Enumeration;
+ import java.util.HashMap;
+ import java.util.Map;
+ 
++import javax.inject.Inject;
++
+ public class NetworkStateListener implements StateListener<State, Event, Network> {
+ 
 -    protected UsageEventDao _usageEventDao;
 -    protected NetworkDao _networkDao;
++    @Inject protected UsageEventDao _usageEventDao;
++    @Inject protected NetworkDao _networkDao;
+ 
+     // get the event bus provider if configured
 -    protected static EventBus _eventBus = null;
 -    static {
 -        Adapters<EventBus> eventBusImpls = ComponentLocator.getLocator(ManagementServer.Name).getAdapters(EventBus.class);
 -        if (eventBusImpls != null) {
 -            Enumeration<EventBus> eventBusenum = eventBusImpls.enumeration();
 -            if (eventBusenum != null && eventBusenum.hasMoreElements()) {
 -                _eventBus = eventBusenum.nextElement(); // configure event bus if configured
 -            }
 -        }
 -    }
++    @Inject protected EventBus _eventBus;
+ 
+     private static final Logger s_logger = Logger.getLogger(NetworkStateListener.class);
+ 
+     public NetworkStateListener(UsageEventDao usageEventDao, NetworkDao networkDao) {
+         this._usageEventDao = usageEventDao;
+         this._networkDao = networkDao;
+     }
+ 
+     @Override
+     public boolean preStateTransitionEvent(State oldState, Event event, State newState, Network vo, boolean status, Object opaque) {
+         pubishOnEventBus(event.name(), "preStateTransitionEvent", vo, oldState, newState);
+         return true;
+     }
+ 
+     @Override
+     public boolean postStateTransitionEvent(State oldState, Event event, State newState, Network vo, boolean status, Object opaque) {
+         pubishOnEventBus(event.name(), "postStateTransitionEvent", vo, oldState, newState);
+         return true;
+     }
+ 
+     private void pubishOnEventBus(String event, String status, Network vo, State oldState, State newState) {
+ 
+         if (_eventBus == null) {
+             return; // no provider is configured to provide events bus, so just return
+         }
+ 
+         String resourceName = getEntityFromClassName(Network.class.getName());
+         org.apache.cloudstack.framework.events.Event eventMsg =  new org.apache.cloudstack.framework.events.Event(
+                 ManagementServer.Name,
+                 EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(),
+                 event,
+                 resourceName,
+                 vo.getUuid());
+         Map<String, String> eventDescription = new HashMap<String, String>();
+         eventDescription.put("resource", resourceName);
+         eventDescription.put("id", vo.getUuid());
+         eventDescription.put("old-state", oldState.name());
+         eventDescription.put("new-state", newState.name());
+         eventMsg.setDescription(eventDescription);
+         try {
+             _eventBus.publish(eventMsg);
+         } catch (EventBusException e) {
+             s_logger.warn("Failed to publish state change event on the the event bus.");
+         }
+     }
+ 
+     private String getEntityFromClassName(String entityClassName) {
+         int index = entityClassName.lastIndexOf(".");
+         String entityName = entityClassName;
+         if (index != -1) {
+             entityName = entityClassName.substring(index+1);
+         }
+         return entityName;
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/dao/NetworkDao.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/dao/NetworkDao.java
index 342a2c5,18dcb6f..1d3f0b8
--- a/server/src/com/cloud/network/dao/NetworkDao.java
+++ b/server/src/com/cloud/network/dao/NetworkDao.java
@@@ -21,11 -21,15 +21,13 @@@ import java.util.Map
  
  import com.cloud.network.Network;
  import com.cloud.network.Network.GuestType;
 -import com.cloud.network.NetworkAccountVO;
 -import com.cloud.network.NetworkVO;
  import com.cloud.network.Networks.TrafficType;
+ import com.cloud.network.Network.State;
  import com.cloud.utils.db.GenericDao;
  import com.cloud.utils.db.SearchBuilder;
+ import com.cloud.utils.fsm.StateDao;
  
- public interface NetworkDao extends GenericDao<NetworkVO, Long> {
+ public interface NetworkDao extends GenericDao<NetworkVO, Long> , StateDao<State, Network.Event, Network> {
  
      List<NetworkVO> listByOwner(long ownerId);
  

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/dao/NetworkDaoImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/dao/NetworkDaoImpl.java
index 60f421b,2c5b46d..8fadf04
--- a/server/src/com/cloud/network/dao/NetworkDaoImpl.java
+++ b/server/src/com/cloud/network/dao/NetworkDaoImpl.java
@@@ -32,6 -28,13 +32,8 @@@ import com.cloud.network.Network
  import com.cloud.network.Network.GuestType;
  import com.cloud.network.Network.Provider;
  import com.cloud.network.Network.Service;
+ import com.cloud.network.Network.State;
+ import com.cloud.network.Network.Event;
 -import com.cloud.network.NetworkAccountDaoImpl;
 -import com.cloud.network.NetworkAccountVO;
 -import com.cloud.network.NetworkDomainVO;
 -import com.cloud.network.NetworkServiceMapVO;
 -import com.cloud.network.NetworkVO;
  import com.cloud.network.Networks.BroadcastDomainType;
  import com.cloud.network.Networks.Mode;
  import com.cloud.network.Networks.TrafficType;
@@@ -40,20 -43,19 +42,17 @@@ import com.cloud.offerings.NetworkOffer
  import com.cloud.offerings.dao.NetworkOfferingDaoImpl;
  import com.cloud.server.ResourceTag.TaggedResourceType;
  import com.cloud.tags.dao.ResourceTagsDaoImpl;
 -import com.cloud.utils.component.ComponentLocator;
 +import com.cloud.utils.db.DB;
 +import com.cloud.utils.db.GenericDaoBase;
 +import com.cloud.utils.db.GenericSearchBuilder;
 +import com.cloud.utils.db.JoinBuilder;
+ import com.cloud.utils.db.*;
  import com.cloud.utils.db.JoinBuilder.JoinType;
- 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;
- import com.cloud.utils.db.SequenceFetcher;
- import com.cloud.utils.db.Transaction;
  import com.cloud.utils.net.NetUtils;
  
 -import javax.ejb.Local;
 -import javax.persistence.TableGenerator;
 -import java.util.List;
 -import java.util.Map;
 -import java.util.Random;
 -
 +@Component
  @Local(value = NetworkDao.class)
  @DB(txn = false)
  public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements NetworkDao {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/dao/NetworkVO.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/dao/NetworkVO.java
index 5ecb22f,0000000..d51a065
mode 100644,000000..100644
--- a/server/src/com/cloud/network/dao/NetworkVO.java
+++ b/server/src/com/cloud/network/dao/NetworkVO.java
@@@ -1,523 -1,0 +1,524 @@@
 +// Licensed to the Apache Software Foundation (ASF) under one
 +// or more contributor license agreements.  See the NOTICE file
 +// distributed with this work for additional information
 +// regarding copyright ownership.  The ASF licenses this file
 +// to you under the Apache License, Version 2.0 (the
 +// "License"); you may not use this file except in compliance
 +// with the License.  You may obtain a copy of the License at
 +//
 +//   http://www.apache.org/licenses/LICENSE-2.0
 +//
 +// Unless required by applicable law or agreed to in writing,
 +// software distributed under the License is distributed on an
 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 +// KIND, either express or implied.  See the License for the
 +// specific language governing permissions and limitations
 +// under the License.
 +package com.cloud.network.dao;
 +
 +import java.net.URI;
 +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.Id;
 +import javax.persistence.Table;
 +import javax.persistence.TableGenerator;
 +import javax.persistence.Transient;
 +
 +import org.apache.cloudstack.acl.ControlledEntity;
 +
 +import com.cloud.network.Network;
 +import com.cloud.network.Networks;
 +import com.cloud.network.Network.GuestType;
 +import com.cloud.network.Network.State;
 +import com.cloud.network.Networks.BroadcastDomainType;
 +import com.cloud.network.Networks.Mode;
 +import com.cloud.network.Networks.TrafficType;
 +import com.cloud.utils.NumbersUtil;
 +import com.cloud.utils.db.GenericDao;
 +import com.cloud.utils.net.NetUtils;
 +
 +/**
 + * NetworkConfigurationVO contains information about a specific network.
 + *
 + */
 +@Entity
 +@Table(name="networks")
 +public class NetworkVO implements Network {
 +    @Id
 +    @TableGenerator(name="networks_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="networks_seq", allocationSize=1)
 +    @Column(name="id")
 +    long id;
 +
 +    @Column(name="mode")
 +    @Enumerated(value=EnumType.STRING)
 +    Mode mode;
 +
 +    @Column(name="broadcast_domain_type")
 +    @Enumerated(value=EnumType.STRING)
 +    BroadcastDomainType broadcastDomainType;
 +
 +    @Column(name="traffic_type")
 +    @Enumerated(value=EnumType.STRING)
 +    TrafficType trafficType;
 +
 +    @Column(name="name")
 +    String name;
 +
 +    @Column(name="display_text")
 +    String displayText;;
 +
 +    @Column(name="broadcast_uri")
 +    URI broadcastUri;
 +
 +    @Column(name="gateway")
 +    String gateway;
 +
 +    @Column(name="cidr")
 +    String cidr;
 +
 +    @Column(name="network_offering_id")
 +    long networkOfferingId;
 +
 +    @Column(name="vpc_id")
 +    Long vpcId;
 +
 +    @Column(name="physical_network_id")
 +    Long physicalNetworkId;
 +
 +    @Column(name="data_center_id")
 +    long dataCenterId;
 +
 +    @Column(name="related")
 +    long related;
 +
 +    @Column(name="guru_name")
 +    String guruName;
 +
 +    @Column(name="state")
 +    @Enumerated(value=EnumType.STRING)
 +    State state;
 +
 +    @Column(name="dns1")
 +    String dns1;
 +
 +    @Column(name="domain_id")
 +    long domainId;
 +
 +    @Column(name="account_id")
 +    long accountId;
 +
 +    @Column(name="set_fields")
 +    long setFields;
 +
 +    @TableGenerator(name="mac_address_seq", table="op_networks", pkColumnName="id", valueColumnName="mac_address_seq", allocationSize=1)
 +    @Transient
 +    long macAddress = 1;
 +
 +    @Column(name="guru_data", length=1024)
 +    String guruData;
 +
 +    @Column(name="dns2")
 +    String dns2;
 +
 +    @Column(name="network_domain")
 +    String networkDomain;
 +
 +    @Column(name=GenericDao.REMOVED_COLUMN)
 +    Date removed;
 +
 +    @Column(name=GenericDao.CREATED_COLUMN)
 +    Date created;
 +
 +    @Column(name="reservation_id")
 +    String reservationId;
 +
 +    @Column(name="uuid")
 +    String uuid;
 +
 +    @Column(name="guest_type")
 +    @Enumerated(value=EnumType.STRING)
 +    Network.GuestType guestType;
 +
 +    @Column(name="acl_type")
 +    @Enumerated(value=EnumType.STRING)
 +    ControlledEntity.ACLType aclType;
 +
 +    @Column(name="restart_required")
 +    boolean restartRequired = false;
 +
 +    @Column(name="specify_ip_ranges")
 +    boolean specifyIpRanges = false;
 +
 +    @Column(name="ip6_gateway")
 +    String ip6Gateway;
 +
 +    @Column(name="ip6_cidr")
 +    String ip6Cidr;
 +
 +    public NetworkVO() {
 +    	this.uuid = UUID.randomUUID().toString();
 +    }
 +
 +    /**
 +     * Constructor to be used for the adapters because it only initializes what's needed.
 +     * @param trafficType
 +     * @param mode
 +     * @param broadcastDomainType
 +     * @param networkOfferingId
 +     * @param state TODO
 +     * @param dataCenterId
 +     * @param physicalNetworkId TODO
 +     */
 +    public NetworkVO(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId,
 +            State state, long dataCenterId, Long physicalNetworkId) {
 +        this.trafficType = trafficType;
 +        this.mode = mode;
 +        this.broadcastDomainType = broadcastDomainType;
 +        this.networkOfferingId = networkOfferingId;
 +        this.dataCenterId = dataCenterId;
 +        this.physicalNetworkId = physicalNetworkId;
 +        if (state == null) {
 +            state = State.Allocated;
 +        } else {
 +            this.state = state;
 +        }
 +        this.id = -1;
 +    	this.uuid = UUID.randomUUID().toString();
 +    }
 +
 +    public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId,
 +            long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId,
 +            Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) {
 +        this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId,
 +                related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges, vpcId);
 +        this.gateway = that.getGateway();
 +        this.cidr = that.getCidr();
 +        this.broadcastUri = that.getBroadcastUri();
 +        this.broadcastDomainType = that.getBroadcastDomainType();
 +        this.guruName = guruName;
 +        this.state = that.getState();
 +        if (state == null) {
 +            state = State.Allocated;
 +        }
 +    	this.uuid = UUID.randomUUID().toString();
 +    	this.ip6Gateway = that.getIp6Gateway();
 +    	this.ip6Cidr = that.getIp6Cidr();
 +    }
 +
 +    /**
 +     * Constructor for the actual DAO object.
 +     * @param trafficType
 +     * @param mode
 +     * @param broadcastDomainType
 +     * @param networkOfferingId
 +     * @param domainId
 +     * @param accountId
 +     * @param name
 +     * @param displayText
 +     * @param networkDomain
 +     * @param guestType TODO
 +     * @param aclType TODO
 +     * @param specifyIpRanges TODO
 +     * @param vpcId TODO
 +     * @param dataCenterId
 +     */
 +    public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType,
 +            long networkOfferingId, long domainId, long accountId, long related, String name, String displayText,
 +            String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) {
 +        this(trafficType, mode, broadcastDomainType, networkOfferingId, State.Allocated, dcId, physicalNetworkId);
 +        this.domainId = domainId;
 +        this.accountId = accountId;
 +        this.related = related;
 +        this.id = id;
 +        this.name = name;
 +        this.displayText = displayText;
 +        this.aclType = aclType;
 +        this.networkDomain = networkDomain;
 +    	this.uuid = UUID.randomUUID().toString();
 +        this.guestType = guestType;
 +        this.specifyIpRanges = specifyIpRanges;
 +        this.vpcId = vpcId;
 +    }
 +
 +    @Override
 +    public String getReservationId() {
 +        return reservationId;
 +    }
 +
 +    public void setReservationId(String reservationId) {
 +        this.reservationId = reservationId;
 +    }
 +
 +    @Override
 +    public State getState() {
 +        return state;
 +    }
 +
++    // don't use this directly when possible, use Network state machine instead
 +    public void setState(State state) {
 +        this.state = state;
 +    }
 +
 +    @Override
 +    public long getRelated() {
 +        return related;
 +    }
 +
 +    @Override
 +    public long getId() {
 +        return id;
 +    }
 +
 +    @Override
 +    public Mode getMode() {
 +        return mode;
 +    }
 +
 +    @Override
 +    public long getAccountId() {
 +        return accountId;
 +    }
 +
 +    @Override
 +    public long getDomainId() {
 +        return domainId;
 +    }
 +
 +    @Override
 +    public long getNetworkOfferingId() {
 +        return networkOfferingId;
 +    }
 +
 +    public void setNetworkOfferingId(long networkOfferingId) {
 +        this.networkOfferingId = networkOfferingId;
 +    }
 +
 +    public void setMode(Mode mode) {
 +        this.mode = mode;
 +    }
 +
 +    @Override
 +    public BroadcastDomainType getBroadcastDomainType() {
 +        return broadcastDomainType;
 +    }
 +
 +    public String getGuruData() {
 +        return guruData;
 +    }
 +
 +    public void setGuruData(String guruData) {
 +        this.guruData = guruData;
 +    }
 +
 +    public String getGuruName() {
 +        return guruName;
 +    }
 +
 +    public void setGuruName(String guruName) {
 +        this.guruName = guruName;
 +    }
 +
 +    public void setBroadcastDomainType(BroadcastDomainType broadcastDomainType) {
 +        this.broadcastDomainType = broadcastDomainType;
 +    }
 +
 +    @Override
 +    public String getNetworkDomain() {
 +        return networkDomain;
 +    }
 +
 +    public void setNetworkDomain(String networkDomain) {
 +        this.networkDomain = networkDomain;
 +    }
 +
 +    @Override
 +    public TrafficType getTrafficType() {
 +        return trafficType;
 +    }
 +
 +    public void setTrafficType(TrafficType trafficType) {
 +        this.trafficType = trafficType;
 +    }
 +
 +    @Override
 +    public String getGateway() {
 +        return gateway;
 +    }
 +
 +    public void setGateway(String gateway) {
 +        this.gateway = gateway;
 +    }
 +
 +    @Override
 +    public String getCidr() {
 +        return cidr;
 +    }
 +
 +    public void setCidr(String cidr) {
 +        this.cidr = cidr;
 +    }
 +
 +    @Override
 +    public URI getBroadcastUri() {
 +        return broadcastUri;
 +    }
 +
 +    public void setBroadcastUri(URI broadcastUri) {
 +        this.broadcastUri = broadcastUri;
 +    }
 +
 +    @Override
 +    public int hashCode() {
 +        return NumbersUtil.hash(id);
 +    }
 +
 +    @Override
 +    public Long getPhysicalNetworkId() {
 +        return physicalNetworkId;
 +    }
 +
 +    @Override
 +    public void setPhysicalNetworkId(Long physicalNetworkId) {
 +        this.physicalNetworkId = physicalNetworkId;
 +    }
 +
 +    @Override
 +    public long getDataCenterId() {
 +        return dataCenterId;
 +    }
 +
 +    public String getDns1() {
 +        return dns1;
 +    }
 +
 +    public void setDns1(String dns) {
 +        this.dns1 = dns;
 +    }
 +
 +    public String getDns2() {
 +        return dns2;
 +    }
 +
 +    public void setDns2(String dns) {
 +        this.dns2 = dns;
 +    }
 +
 +    @Override
 +    public String getName() {
 +        return name;
 +    }
 +
 +    public void setName(String name) {
 +        this.name = name;
 +    }
 +
 +    @Override
 +    public String getDisplayText() {
 +        return displayText;
 +    }
 +
 +    public void setDisplayText(String displayText) {
 +        this.displayText = displayText;
 +    }
 +
 +    public Date getRemoved() {
 +        return removed;
 +    }
 +
 +    public void setRemoved(Date removed) {
 +        this.removed = removed;
 +    }
 +
 +    public Date getCreated() {
 +        return created;
 +    }
 +
 +    public void setCreated(Date created) {
 +        this.created = created;
 +    }
 +
 +    @Override
 +    public Network.GuestType getGuestType() {
 +        return guestType;
 +    }
 +
 +    @Override
 +    public boolean equals(Object obj) {
 +        if (!(obj instanceof NetworkVO)) {
 +            return false;
 +        }
 +        NetworkVO that = (NetworkVO)obj;
 +        if (this.trafficType != that.trafficType) {
 +            return false;
 +        }
 +
 +        if ((this.cidr == null && that.cidr != null) || (this.cidr != null && that.cidr == null)) {
 +            return false;
 +        }
 +
 +        if (this.cidr == null && that.cidr == null) {
 +            return true;
 +        }
 +
 +        return NetUtils.isNetworkAWithinNetworkB(this.cidr, that.cidr);
 +    }
 +
 +    @Override
 +    public String toString() {
 +        StringBuilder buf = new StringBuilder("Ntwk[");
 +        buf.append(id).append("|").append(trafficType).append("|").append(networkOfferingId).append("]");
 +        return buf.toString();
 +    }
 +
 +    public String getUuid() {
 +    	return this.uuid;
 +    }
 +
 +    public void setUuid(String uuid) {
 +    	this.uuid = uuid;
 +    }
 +
 +	public ControlledEntity.ACLType getAclType() {
 +		return aclType;
 +	}
 +
 +	public void setRestartRequired(boolean restartRequired) {
 +		this.restartRequired = restartRequired;
 +	}
 +
 +	@Override
 +	public boolean isRestartRequired() {
 +		return restartRequired;
 +	}
 +
 +    @Override
 +    public boolean getSpecifyIpRanges() {
 +    	return specifyIpRanges;
 +    }
 +
 +    @Override
 +    public Long getVpcId() {
 +        return vpcId;
 +    }
 +
 +	public String getIp6Cidr() {
 +		return ip6Cidr;
 +	}
 +
 +	public void setIp6Cidr(String ip6Cidr) {
 +		this.ip6Cidr = ip6Cidr;
 +	}
 +
 +	public String getIp6Gateway() {
 +		return ip6Gateway;
 +	}
 +
 +	public void setIp6Gateway(String ip6Gateway) {
 +		this.ip6Gateway = ip6Gateway;
 +	}
 +}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/dao/UserIpv6AddressDaoImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/firewall/FirewallManagerImpl.java
index 7bce18c,a3f60cb..d3b4c0b
--- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
+++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
@@@ -85,15 -79,11 +80,14 @@@ import com.cloud.user.DomainManager
  import com.cloud.user.UserContext;
  import com.cloud.utils.Pair;
  import com.cloud.utils.Ternary;
- import com.cloud.utils.component.Manager;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.Inject;
 -import com.cloud.utils.component.Manager;
 +import com.cloud.utils.component.ManagerBase;
 +import com.cloud.utils.db.DB;
 +import com.cloud.utils.db.Filter;
 +import com.cloud.utils.db.JoinBuilder;
 +import com.cloud.utils.db.SearchBuilder;
 +import com.cloud.utils.db.SearchCriteria;
+ import com.cloud.utils.db.*;
  import com.cloud.utils.db.SearchCriteria.Op;
- import com.cloud.utils.db.Transaction;
  import com.cloud.utils.exception.CloudRuntimeException;
  import com.cloud.utils.net.NetUtils;
  import com.cloud.vm.UserVmVO;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
index 37cd7d4,519ad26..b1606db
--- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
@@@ -19,8 -19,8 +19,9 @@@ package com.cloud.network.guru
  import java.util.List;
  
  import javax.ejb.Local;
 +import javax.inject.Inject;
  
+ import com.cloud.event.ActionEventUtils;
  import org.apache.log4j.Logger;
  
  import com.cloud.configuration.Config;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/guru/GuestNetworkGuru.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/guru/GuestNetworkGuru.java
index bca5114,dc23b72..ab8a069
--- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
@@@ -24,10 -23,9 +23,11 @@@ import java.util.SortedSet
  import java.util.TreeSet;
  
  import javax.ejb.Local;
 +import javax.inject.Inject;
  
+ import com.cloud.event.ActionEventUtils;
  import org.apache.log4j.Logger;
 +import org.springframework.stereotype.Component;
  
  import com.cloud.configuration.Config;
  import com.cloud.configuration.dao.ConfigurationDao;
@@@ -432,12 -429,12 +431,12 @@@ public abstract class GuestNetworkGuru 
          
          if (profile.getBroadcastDomainType() == BroadcastDomainType.Vlan && 
          		profile.getBroadcastUri() != null && !offering.getSpecifyVlan()) {
 -        	s_logger.debug("Releasing vnet for the network id=" + profile.getId());
 +        s_logger.debug("Releasing vnet for the network id=" + profile.getId());
              _dcDao.releaseVnet(profile.getBroadcastUri().getHost(), profile.getDataCenterId(), 
                      profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId());
-             EventUtils.saveEvent(UserContext.current().getCallerUserId(), profile.getAccountId(), 
+             ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallerUserId(), profile.getAccountId(),
                      EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE, "Released Zone Vlan: "
-                     +profile.getBroadcastUri().getHost()+" for Network: "+profile.getId(), 0);
+                     + profile.getBroadcastUri().getHost() + " for Network: " + profile.getId(), 0);
          }
          profile.setBroadcastUri(null);
      }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index 653a4d3,8e47545..85e850c
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@@ -28,19 -28,16 +28,20 @@@ import java.util.Map
  import java.util.Set;
  
  import javax.ejb.Local;
 -import javax.naming.ConfigurationException;
 +import javax.inject.Inject;
- import javax.naming.ConfigurationException;
+ 
+ import com.cloud.event.UsageEventUtils;
 -import org.apache.cloudstack.api.command.user.loadbalancer.*;
+ import org.apache.log4j.Logger;
  
  import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBStickinessPolicyCmd;
 +import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
 +import org.apache.cloudstack.api.command.user.loadbalancer.ListLBStickinessPoliciesCmd;
  import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRuleInstancesCmd;
  import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRulesCmd;
 +import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd;
  import org.apache.cloudstack.api.response.ServiceResponse;
- import org.apache.log4j.Logger;
 +import org.springframework.stereotype.Component;
 +
  import com.cloud.configuration.Config;
  import com.cloud.configuration.ConfigurationManager;
  import com.cloud.configuration.dao.ConfigurationDao;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
index 54864b3,5635f52..eafe88e
--- a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
+++ b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
@@@ -72,13 -36,9 +67,14 @@@ import com.cloud.network.NetworkManager
  import com.cloud.network.NetworkModel;
  import com.cloud.network.security.SecurityGroupWork.Step;
  import com.cloud.network.security.SecurityRule.SecurityRuleType;
 +import com.cloud.network.security.dao.SecurityGroupDao;
 +import com.cloud.network.security.dao.SecurityGroupRuleDao;
 +import com.cloud.network.security.dao.SecurityGroupRulesDao;
 +import com.cloud.network.security.dao.SecurityGroupVMMapDao;
 +import com.cloud.network.security.dao.SecurityGroupWorkDao;
 +import com.cloud.network.security.dao.VmRulesetLogDao;
+ import com.cloud.network.security.dao.*;
  import com.cloud.projects.ProjectManager;
 -import com.cloud.server.ManagementServer;
  import com.cloud.tags.dao.ResourceTagDao;
  import com.cloud.user.Account;
  import com.cloud.user.AccountManager;
@@@ -98,22 -59,25 +94,17 @@@ import com.cloud.utils.db.Transaction
  import com.cloud.utils.exception.CloudRuntimeException;
  import com.cloud.utils.fsm.StateListener;
  import com.cloud.utils.net.NetUtils;
- import com.cloud.vm.Nic;
- import com.cloud.vm.NicProfile;
- import com.cloud.vm.UserVmManager;
- import com.cloud.vm.UserVmVO;
- import com.cloud.vm.VMInstanceVO;
- import com.cloud.vm.VirtualMachine;
+ import com.cloud.vm.*;
  import com.cloud.vm.VirtualMachine.Event;
  import com.cloud.vm.VirtualMachine.State;
- import com.cloud.vm.VirtualMachineManager;
  import com.cloud.vm.dao.UserVmDao;
  import com.cloud.vm.dao.VMInstanceDao;
- 
  import edu.emory.mathcs.backport.java.util.Collections;
+ import org.apache.cloudstack.api.command.user.securitygroup.*;
 -import org.apache.commons.codec.digest.DigestUtils;
 -import org.apache.log4j.Logger;
 -
 -import javax.ejb.Local;
 -import javax.naming.ConfigurationException;
+ import java.util.*;
 -import java.util.concurrent.Executors;
 -import java.util.concurrent.ScheduledExecutorService;
 -import java.util.concurrent.TimeUnit;
  
  @Local(value = { SecurityGroupManager.class, SecurityGroupService.class })
 -public class SecurityGroupManagerImpl implements SecurityGroupManager, SecurityGroupService, Manager, StateListener<State, VirtualMachine.Event, VirtualMachine> {
 +public class SecurityGroupManagerImpl extends ManagerBase implements SecurityGroupManager, SecurityGroupService, StateListener<State, VirtualMachine.Event, VirtualMachine> {
      public static final Logger s_logger = Logger.getLogger(SecurityGroupManagerImpl.class);
  
      @Inject
@@@ -458,8 -420,9 +447,9 @@@
          // For each group, find the security rules that allow the group
          for (SecurityGroupVMMapVO mapVO : groupsForVm) {// FIXME: use custom sql in the dao
          	//Add usage events for security group assign
-             UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SECURITY_GROUP_ASSIGN, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), mapVO.getSecurityGroupId());
-             _usageEventDao.persist(usageEvent);
+             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SECURITY_GROUP_ASSIGN, vm.getAccountId(),
 -                    vm.getDataCenterIdToDeployIn(), vm.getId(), mapVO.getSecurityGroupId(),
++                    vm.getDataCenterId(), vm.getId(), mapVO.getSecurityGroupId(),
+                     vm.getClass().getName(), vm.getUuid());
  
              List<SecurityGroupRuleVO> allowingRules = _securityGroupRuleDao.listByAllowedSecurityGroupId(mapVO.getSecurityGroupId());
              // For each security rule that allows a group that the vm belongs to, find the group it belongs to
@@@ -474,8 -437,9 +464,9 @@@
          // For each group, find the security rules rules that allow the group
          for (SecurityGroupVMMapVO mapVO : groupsForVm) {// FIXME: use custom sql in the dao
          	//Add usage events for security group remove
-             UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SECURITY_GROUP_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), mapVO.getSecurityGroupId());
-             _usageEventDao.persist(usageEvent);
+             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SECURITY_GROUP_REMOVE,
 -                    vm.getAccountId(), vm.getDataCenterIdToDeployIn(), vm.getId(), mapVO.getSecurityGroupId(),
++                    vm.getAccountId(), vm.getDataCenterId(), vm.getId(), mapVO.getSecurityGroupId(),
+                     vm.getClass().getName(), vm.getUuid());
  
              List<SecurityGroupRuleVO> allowingRules = _securityGroupRuleDao.listByAllowedSecurityGroupId(mapVO.getSecurityGroupId());
              // For each security rule that allows a group that the vm belongs to, find the group it belongs to

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
index d4b2424,858c362..82c0015
--- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
@@@ -41,19 -27,12 +41,19 @@@ import com.cloud.exception.AccountLimit
  import com.cloud.exception.InvalidParameterValueException;
  import com.cloud.exception.NetworkRuleConflictException;
  import com.cloud.exception.ResourceUnavailableException;
 -import com.cloud.network.*;
 +import com.cloud.network.Network;
  import com.cloud.network.Network.Service;
 +import com.cloud.network.NetworkModel;
 +import com.cloud.network.PublicIpAddress;
 +import com.cloud.network.RemoteAccessVpn;
 +import com.cloud.network.VpnUser;
++import com.cloud.network.*;
  import com.cloud.network.VpnUser.State;
- import com.cloud.network.VpnUserVO;
  import com.cloud.network.dao.FirewallRulesDao;
  import com.cloud.network.dao.IPAddressDao;
 +import com.cloud.network.dao.IPAddressVO;
  import com.cloud.network.dao.RemoteAccessVpnDao;
 +import com.cloud.network.dao.RemoteAccessVpnVO;
  import com.cloud.network.dao.VpnUserDao;
  import com.cloud.network.element.RemoteAccessVPNServiceProvider;
  import com.cloud.network.rules.FirewallManager;
@@@ -71,22 -50,29 +71,21 @@@ import com.cloud.utils.NumbersUtil
  import com.cloud.utils.Pair;
  import com.cloud.utils.PasswordGenerator;
  import com.cloud.utils.Ternary;
- import com.cloud.utils.component.Manager;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.ComponentLocator;
 -import com.cloud.utils.component.Inject;
 -import com.cloud.utils.component.Manager;
 +import com.cloud.utils.component.ManagerBase;
 +import com.cloud.utils.db.DB;
 +import com.cloud.utils.db.Filter;
 +import com.cloud.utils.db.JoinBuilder;
 +import com.cloud.utils.db.SearchBuilder;
 +import com.cloud.utils.db.SearchCriteria;
+ import com.cloud.utils.db.*;
  import com.cloud.utils.db.SearchCriteria.Op;
- import com.cloud.utils.db.Transaction;
  import com.cloud.utils.net.NetUtils;
 -import org.apache.cloudstack.api.command.user.vpn.ListRemoteAccessVpnsCmd;
 -import org.apache.cloudstack.api.command.user.vpn.ListVpnUsersCmd;
 -import org.apache.log4j.Logger;
 -
 -import javax.ejb.Local;
 -import javax.naming.ConfigurationException;
 -import java.util.ArrayList;
 -import java.util.Enumeration;
 -import java.util.List;
 -import java.util.Map;
  
 +@Component
  @Local(value = RemoteAccessVpnService.class)
 -public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manager {
 +public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAccessVpnService {
      private final static Logger s_logger = Logger.getLogger(RemoteAccessVpnManagerImpl.class);
 -    String _name;
 -    
 +
      @Inject AccountDao _accountDao;
      @Inject VpnUserDao _vpnUsersDao;
      @Inject RemoteAccessVpnDao _remoteAccessVpnDao;
@@@ -278,11 -264,11 +277,11 @@@
                          // Stop billing of VPN users when VPN is removed. VPN_User_ADD events will be generated when VPN is created again 
                          List<VpnUserVO> vpnUsers = _vpnUsersDao.listByAccount(vpn.getAccountId());
                          for(VpnUserVO user : vpnUsers){
 -                        	// VPN_USER_REMOVE event is already generated for users in Revoke state
 -                        	if(user.getState() != VpnUser.State.Revoke){
 +                            // VPN_USER_REMOVE event is already generated for users in Revoke state
 +                            if(user.getState() != VpnUser.State.Revoke){
-                                 UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VPN_USER_REMOVE, user.getAccountId(), 0, user.getId(), user.getUsername());
-                                 _usageEventDao.persist(usageEvent);
+                                 UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPN_USER_REMOVE, user.getAccountId(),
+                                         0, user.getId(), user.getUsername(), user.getClass().getName(), user.getUuid());
 -                        	}
 +                            }
                          }
                          if (vpnFwRules != null) {
                              for (FirewallRule vpnFwRule : vpnFwRules) {
@@@ -330,10 -316,10 +329,10 @@@
          if (userCount >= _userLimit) {
              throw new AccountLimitException("Cannot add more than " + _userLimit + " remote access vpn users");
          }
 -        
 +
          VpnUser user = _vpnUsersDao.persist(new VpnUserVO(vpnOwnerId, owner.getDomainId(), username, password));
-         UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VPN_USER_ADD, user.getAccountId(), 0, user.getId(), user.getUsername());
-         _usageEventDao.persist(usageEvent);
+         UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPN_USER_ADD, user.getAccountId(), 0, user.getId(),
+                 user.getUsername(), user.getClass().getName(), user.getUuid());
          txn.commit();
          return user;
      }
@@@ -405,10 -391,10 +404,10 @@@
                  // Start billing of existing VPN users in ADD and Active state 
                  List<VpnUserVO> vpnUsers = _vpnUsersDao.listByAccount(vpn.getAccountId());
                  for(VpnUserVO user : vpnUsers){
 -                	if(user.getState() != VpnUser.State.Revoke){
 +                    if(user.getState() != VpnUser.State.Revoke){
-                         UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VPN_USER_ADD, user.getAccountId(), 0, user.getId(), user.getUsername());
-                         _usageEventDao.persist(usageEvent);
+                         UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPN_USER_ADD, user.getAccountId(), 0,
+                                 user.getId(), user.getUsername(), user.getClass().getName(), user.getUuid());
 -                	}
 +                    }
                  }
                  txn.commit();
              } 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/projects/ProjectManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/projects/ProjectManagerImpl.java
index 72ed940,f65627e..45a9a24
--- a/server/src/com/cloud/projects/ProjectManagerImpl.java
+++ b/server/src/com/cloud/projects/ProjectManagerImpl.java
@@@ -203,9 -205,9 +203,9 @@@ public class ProjectManagerImpl extend
          //Create an account associated with the project
          StringBuilder acctNm = new StringBuilder("PrjAcct-");
          acctNm.append(name).append("-").append(owner.getDomainId());
 -        
 +
-         Account projectAccount = _accountMgr.createAccount(acctNm.toString(), Account.ACCOUNT_TYPE_PROJECT, domainId, null, null);
+         Account projectAccount = _accountMgr.createAccount(acctNm.toString(), Account.ACCOUNT_TYPE_PROJECT, domainId, null, null, "", 0);
 -        
 +
          Project project = _projectDao.persist(new ProjectVO(name, displayText, owner.getDomainId(), projectAccount.getId()));
  
          //assign owner to the project

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/server/ConfigurationServerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/server/ConfigurationServerImpl.java
index b55e949,2ae0843..fa68514
--- a/server/src/com/cloud/server/ConfigurationServerImpl.java
+++ b/server/src/com/cloud/server/ConfigurationServerImpl.java
@@@ -106,42 -71,62 +106,47 @@@ import com.cloud.utils.exception.CloudR
  import com.cloud.utils.net.NetUtils;
  import com.cloud.utils.script.Script;
  import com.cloud.uuididentity.dao.IdentityDao;
 -
+ import org.apache.cloudstack.region.RegionVO;
+ import org.apache.cloudstack.region.dao.RegionDao;
+ import org.apache.commons.codec.binary.Base64;
+ import org.apache.log4j.Logger;
  
 -import javax.crypto.KeyGenerator;
 -import javax.crypto.SecretKey;
 -import java.io.*;
 -import java.net.InetAddress;
 -import java.net.UnknownHostException;
 -import java.security.NoSuchAlgorithmException;
 -import java.sql.PreparedStatement;
 -import java.sql.ResultSet;
 -import java.sql.SQLException;
 -import java.util.*;
 -import java.util.regex.Pattern;
 -
 -public class ConfigurationServerImpl implements ConfigurationServer {
 +@Component
 +public class ConfigurationServerImpl extends ManagerBase implements ConfigurationServer {
      public static final Logger s_logger = Logger.getLogger(ConfigurationServerImpl.class.getName());
  
 -    private final ConfigurationDao _configDao;
 -    private final DataCenterDao _zoneDao;
 -    private final HostPodDao _podDao;
 -    private final DiskOfferingDao _diskOfferingDao;
 -    private final ServiceOfferingDao _serviceOfferingDao;
 -    private final NetworkOfferingDao _networkOfferingDao;
 -    private final DataCenterDao _dataCenterDao;
 -    private final NetworkDao _networkDao;
 -    private final VlanDao _vlanDao;
 +    @Inject private ConfigurationDao _configDao;
 +    @Inject private DataCenterDao _zoneDao;
 +    @Inject private HostPodDao _podDao;
 +    @Inject private DiskOfferingDao _diskOfferingDao;
 +    @Inject private ServiceOfferingDao _serviceOfferingDao;
 +    @Inject private NetworkOfferingDao _networkOfferingDao;
 +    @Inject private DataCenterDao _dataCenterDao;
 +    @Inject private NetworkDao _networkDao;
 +    @Inject private VlanDao _vlanDao;    
      private String _domainSuffix;
 -    private final DomainDao _domainDao;
 -    private final AccountDao _accountDao;
 -    private final ResourceCountDao _resourceCountDao;
 -    private final NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao;
 -    private final IdentityDao _identityDao;
 -    private final RegionDao _regionDao;
 +    @Inject private DomainDao _domainDao;
 +    @Inject private AccountDao _accountDao;
 +    @Inject private ResourceCountDao _resourceCountDao;
 +    @Inject private NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao;
 +    @Inject private IdentityDao _identityDao;
++    @Inject private RegionDao _regionDao;
  
      public ConfigurationServerImpl() {
 -        ComponentLocator locator = ComponentLocator.getLocator(Name);
 -        _configDao = locator.getDao(ConfigurationDao.class);
 -        _zoneDao = locator.getDao(DataCenterDao.class);
 -        _podDao = locator.getDao(HostPodDao.class);
 -        _diskOfferingDao = locator.getDao(DiskOfferingDao.class);
 -        _serviceOfferingDao = locator.getDao(ServiceOfferingDao.class);
 -        _networkOfferingDao = locator.getDao(NetworkOfferingDao.class);
 -        _dataCenterDao = locator.getDao(DataCenterDao.class);
 -        _networkDao = locator.getDao(NetworkDao.class);
 -        _vlanDao = locator.getDao(VlanDao.class);
 -        _domainDao = locator.getDao(DomainDao.class);
 -        _accountDao = locator.getDao(AccountDao.class);
 -        _resourceCountDao = locator.getDao(ResourceCountDao.class);
 -        _ntwkOfferingServiceMapDao = locator.getDao(NetworkOfferingServiceMapDao.class);
 -        _identityDao = locator.getDao(IdentityDao.class);
 -        _regionDao = locator.getDao(RegionDao.class);
 +    	setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK_BOOTSTRAP);
      }
 +    
 +	@Override
 +	public boolean configure(String name, Map<String, Object> params)
 +			throws ConfigurationException {
 +		
 +		try {
 +			persistDefaultValues();
 +		} catch (InternalErrorException e) {
 +			throw new RuntimeException("Unhandled configuration exception", e);
 +		}
 +		return true;
 +	}
  
      @Override
      @DB
@@@ -276,12 -263,8 +283,11 @@@
  
          // We should not update seed data UUID column here since this will be invoked in upgrade case as well.
          //updateUuids();
- 
          // Set init to true
          _configDao.update("init", "Hidden", "true");
 +
 +        // invalidate cache in DAO as we have changed DB status
 +        _configDao.invalidateCache();
      }
  
      /*
@@@ -1264,5 -1248,10 +1271,10 @@@
  
          return svcProviders;
      }
 -    
 +
+     private void createDefaultRegion(){
+     	//Get Region name and URL from db.properties    	
+     	_regionDao.persist(new RegionVO(_regionDao.getRegionId(), "Local", "http://localhost:8080/client/api", "", ""));
+     }
+ 
  }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/server/ManagementServerImpl.java
index be612c8,0b5c531..a1d12c5
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@@ -26,9 -26,9 +26,8 @@@ import java.util.ArrayList
  import java.util.Calendar;
  import java.util.Comparator;
  import java.util.Date;
 -import java.util.Enumeration;
  import java.util.HashMap;
  import java.util.HashSet;
- import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
@@@ -38,19 -38,10 +37,21 @@@ import java.util.concurrent.Executors
  import java.util.concurrent.ScheduledExecutorService;
  import java.util.concurrent.TimeUnit;
  
 +import javax.annotation.PostConstruct;
  import javax.crypto.Mac;
  import javax.crypto.spec.SecretKeySpec;
 +import javax.inject.Inject;
 +import javax.management.InstanceAlreadyExistsException;
 +import javax.management.MBeanRegistrationException;
 +import javax.management.MalformedObjectNameException;
 +import javax.management.NotCompliantMBeanException;
 +import javax.naming.ConfigurationException;
 +
 +import com.cloud.storage.dao.*;
 +import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 +import org.apache.cloudstack.api.ApiConstants;
+ 
+ import com.cloud.event.ActionEventUtils;
  import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
  import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
  import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
@@@ -2828,8 -2811,8 +2827,7 @@@ public class ManagementServerImpl exten
              // This means its a new account, set the password using the
              // authenticator
  
-             for (Iterator<UserAuthenticator> en = _userAuthenticators.iterator(); en.hasNext();) {
-                 UserAuthenticator authenticator = en.next();
 -            for (Enumeration<UserAuthenticator> en = _userAuthenticators.enumeration(); en.hasMoreElements();) {
 -                UserAuthenticator authenticator = en.nextElement();
++            for (UserAuthenticator  authenticator: _userAuthenticators) {
                  encodedPassword = authenticator.encode(password);
                  if (encodedPassword != null) {
                      break;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/StorageManagerImpl.java
index 2c59739,5a799f9..45e3a7f
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@@ -16,66 -16,9 +16,47 @@@
  // under the License.
  package com.cloud.storage;
  
 +import java.math.BigDecimal;
 +import java.net.Inet6Address;
 +import java.net.InetAddress;
 +import java.net.URI;
 +import java.net.URISyntaxException;
 +import java.net.UnknownHostException;
 +import java.sql.PreparedStatement;
 +import java.sql.ResultSet;
 +import java.util.ArrayList;
 +import java.util.Collection;
 +import java.util.Collections;
 +import java.util.Date;
 +import java.util.HashMap;
 +import java.util.HashSet;
 +import java.util.Iterator;
 +import java.util.List;
 +import java.util.Map;
 +import java.util.Random;
 +import java.util.Set;
 +import java.util.UUID;
 +import java.util.concurrent.Executors;
 +import java.util.concurrent.ScheduledExecutorService;
 +import java.util.concurrent.TimeUnit;
 +
 +import javax.ejb.Local;
 +import javax.inject.Inject;
 +import javax.naming.ConfigurationException;
 +
 +import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
 +import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
 +import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
 +import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
 +import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
 +import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
 +import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
 +import org.apache.log4j.Logger;
 +import org.springframework.stereotype.Component;
 +
  import com.cloud.agent.AgentManager;
- import com.cloud.agent.api.Answer;
- import com.cloud.agent.api.BackupSnapshotCommand;
- import com.cloud.agent.api.CleanupSnapshotBackupCommand;
- import com.cloud.agent.api.Command;
- import com.cloud.agent.api.CreateStoragePoolCommand;
- import com.cloud.agent.api.CreateVolumeFromSnapshotAnswer;
- import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
- import com.cloud.agent.api.DeleteStoragePoolCommand;
- import com.cloud.agent.api.ManageSnapshotCommand;
- import com.cloud.agent.api.ModifyStoragePoolAnswer;
- import com.cloud.agent.api.ModifyStoragePoolCommand;
- import com.cloud.agent.api.UpgradeSnapshotCommand;
- import com.cloud.agent.api.storage.CopyVolumeAnswer;
- import com.cloud.agent.api.storage.CopyVolumeCommand;
- import com.cloud.agent.api.storage.CreateAnswer;
- import com.cloud.agent.api.storage.CreateCommand;
- import com.cloud.agent.api.storage.DeleteTemplateCommand;
- import com.cloud.agent.api.storage.DeleteVolumeCommand;
- import com.cloud.agent.api.storage.DestroyCommand;
- import com.cloud.agent.api.storage.ResizeVolumeCommand;
- import com.cloud.agent.api.storage.ResizeVolumeAnswer;
+ import com.cloud.agent.api.*;
+ import com.cloud.agent.api.storage.*;
  import com.cloud.agent.api.to.StorageFilerTO;
  import com.cloud.agent.api.to.VolumeTO;
  import com.cloud.agent.manager.Commands;
@@@ -175,44 -92,43 +129,24 @@@ import com.cloud.utils.EnumUtils
  import com.cloud.utils.NumbersUtil;
  import com.cloud.utils.Pair;
  import com.cloud.utils.UriUtils;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.ComponentLocator;
 -import com.cloud.utils.component.Inject;
 +import com.cloud.utils.component.ComponentContext;
  import com.cloud.utils.component.Manager;
 +import com.cloud.utils.component.ManagerBase;
  import com.cloud.utils.concurrency.NamedThreadFactory;
- import com.cloud.utils.db.DB;
- import com.cloud.utils.db.GenericSearchBuilder;
- import com.cloud.utils.db.GlobalLock;
- import com.cloud.utils.db.JoinBuilder;
+ import com.cloud.utils.db.*;
  import com.cloud.utils.db.JoinBuilder.JoinType;
- 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;
  import com.cloud.utils.exception.CloudRuntimeException;
  import com.cloud.utils.exception.ExecutionException;
  import com.cloud.utils.fsm.NoTransitionException;
  import com.cloud.utils.fsm.StateMachine2;
- import com.cloud.vm.ConsoleProxyVO;
- import com.cloud.vm.DiskProfile;
- import com.cloud.vm.DomainRouterVO;
- import com.cloud.vm.SecondaryStorageVmVO;
- import com.cloud.vm.UserVmManager;
- import com.cloud.vm.UserVmVO;
- import com.cloud.vm.VMInstanceVO;
- import com.cloud.vm.VirtualMachine;
+ import com.cloud.vm.*;
  import com.cloud.vm.VirtualMachine.State;
- import com.cloud.vm.VirtualMachineManager;
- import com.cloud.vm.VirtualMachineProfile;
- import com.cloud.vm.VirtualMachineProfileImpl;
- import com.cloud.vm.dao.ConsoleProxyDao;
- import com.cloud.vm.dao.DomainRouterDao;
- import com.cloud.vm.dao.SecondaryStorageVmDao;
- import com.cloud.vm.dao.UserVmDao;
- import com.cloud.vm.dao.VMInstanceDao;
+ import com.cloud.vm.dao.*;
 -import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
 -import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
 -import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
 -import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
 -import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
 -import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
 -import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
 -import org.apache.log4j.Logger;
 -
 -import javax.ejb.Local;
 -import javax.naming.ConfigurationException;
 -import java.math.BigDecimal;
 -import java.net.*;
 -import java.sql.PreparedStatement;
 -import java.sql.ResultSet;
 -import java.util.*;
 -import java.util.concurrent.Executors;
 -import java.util.concurrent.ScheduledExecutorService;
 -import java.util.concurrent.TimeUnit;
  
 +@Component
  @Local(value = { StorageManager.class, StorageService.class })
 -public class StorageManagerImpl implements StorageManager, Manager, ClusterManagerListener {
 +public class StorageManagerImpl extends ManagerBase implements StorageManager, ClusterManagerListener {
      private static final Logger s_logger = Logger.getLogger(StorageManagerImpl.class);
  
      protected String _name;
@@@ -773,14 -688,15 +705,15 @@@
          volume.setPath(cvAnswer.getVolumePath());
          volume.setFolder(destPool.getPath());
          volume.setPodId(destPool.getPodId());
 -        volume.setPoolId(destPool.getId());
 +        volume.setPoolId(destPool.getId());        
          volume.setPodId(destPool.getPodId());
 -        stateTransitTo(volume, Event.CopySucceeded);
 +        stateTransitTo(volume, Event.CopySucceeded); 
-         UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), volume.getDiskOfferingId(), null, volume.getSize());
-         _usageEventDao.persist(usageEvent);
+         UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(),
+                 volume.getDataCenterId(), volume.getId(), volume.getName(), volume.getDiskOfferingId(),
+                 null, volume.getSize(), Volume.class.getName(), volume.getUuid());
          _volumeHostDao.remove(volumeHostVO.getId());
 -    	txn.commit();
 -		return volume;
 +        txn.commit();
 +        return volume;
  
      }
  

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
index 8347c4e,3fe1aba..17bcf9b
--- a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
@@@ -16,38 -16,28 +16,38 @@@
  // under the License.
  package com.cloud.storage.dao;
  
 +import java.sql.PreparedStatement;
 +import java.sql.ResultSet;
 +import java.util.List;
 +
 +import javax.annotation.PostConstruct;
 +import javax.ejb.Local;
 +import javax.inject.Inject;
 +
 +import org.apache.log4j.Logger;
 +import org.springframework.stereotype.Component;
 +
  import com.cloud.server.ResourceTag.TaggedResourceType;
  import com.cloud.storage.Snapshot;
+ import com.cloud.storage.Snapshot.Event;
+ import com.cloud.storage.Snapshot.State;
  import com.cloud.storage.Snapshot.Type;
  import com.cloud.storage.SnapshotVO;
  import com.cloud.storage.Volume;
  import com.cloud.storage.VolumeVO;
  import com.cloud.tags.dao.ResourceTagsDaoImpl;
 -import com.cloud.utils.component.ComponentLocator;
 +
 +import com.cloud.utils.db.DB;
 +import com.cloud.utils.db.Filter;
 +import com.cloud.utils.db.GenericDaoBase;
 +import com.cloud.utils.db.GenericSearchBuilder;
+ import com.cloud.utils.db.*;
  import com.cloud.utils.db.JoinBuilder.JoinType;
- 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;
  import com.cloud.vm.VMInstanceVO;
  import com.cloud.vm.dao.VMInstanceDaoImpl;
 -import org.apache.log4j.Logger;
 -
 -import javax.ejb.Local;
 -import java.sql.PreparedStatement;
 -import java.sql.ResultSet;
 -import java.util.List;
  
 +@Component
  @Local (value={SnapshotDao.class})
  public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements SnapshotDao {
      public static final Logger s_logger = Logger.getLogger(SnapshotDaoImpl.class.getName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/download/DownloadMonitorImpl.java
index 2f8d757,cf51567..6d3cf2a
--- a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
+++ b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java
@@@ -93,14 -51,9 +68,13 @@@ import com.cloud.storage.template.Templ
  import com.cloud.storage.template.TemplateInfo;
  import com.cloud.user.Account;
  import com.cloud.user.ResourceLimitService;
 -import com.cloud.utils.component.Inject;
 -import com.cloud.utils.db.*;
 +import com.cloud.utils.component.ManagerBase;
 +import com.cloud.utils.db.DB;
 +import com.cloud.utils.db.JoinBuilder;
 +import com.cloud.utils.db.SearchBuilder;
 +import com.cloud.utils.db.SearchCriteria;
 +import com.cloud.utils.db.Transaction;
  import com.cloud.utils.exception.CloudRuntimeException;
- import com.cloud.utils.fsm.NoTransitionException;
  import com.cloud.vm.SecondaryStorageVm;
  import com.cloud.vm.SecondaryStorageVmVO;
  import com.cloud.vm.UserVmManager;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/storage/listener/SnapshotStateListener.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/listener/SnapshotStateListener.java
index 0000000,d0ca389..17ccce5
mode 000000,100644..100644
--- a/server/src/com/cloud/storage/listener/SnapshotStateListener.java
+++ b/server/src/com/cloud/storage/listener/SnapshotStateListener.java
@@@ -1,0 -1,102 +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.storage.listener;
+ 
+ import com.cloud.event.EventCategory;
+ import com.cloud.storage.Snapshot;
+ import com.cloud.storage.Snapshot.Event;
+ import com.cloud.storage.Snapshot.State;
+ import com.cloud.server.ManagementServer;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.ComponentLocator;
+ import com.cloud.utils.fsm.StateListener;
++
+ import org.apache.cloudstack.framework.events.EventBus;
+ import org.apache.cloudstack.framework.events.EventBusException;
+ import org.apache.log4j.Logger;
+ 
+ import java.util.Enumeration;
+ import java.util.HashMap;
+ import java.util.Map;
+ 
++import javax.inject.Inject;
++
+ public class SnapshotStateListener implements StateListener<State, Event, Snapshot> {
+ 
+     // get the event bus provider if configured
 -    protected static EventBus _eventBus = null;
 -    static {
 -        Adapters<EventBus> eventBusImpls = ComponentLocator.getLocator(ManagementServer.Name).getAdapters(EventBus.class);
 -        if (eventBusImpls != null) {
 -            Enumeration<EventBus> eventBusenum = eventBusImpls.enumeration();
 -            if (eventBusenum != null && eventBusenum.hasMoreElements()) {
 -                _eventBus = eventBusenum.nextElement(); // configure event bus if configured
 -            }
 -        }
 -    }
++    @Inject protected EventBus _eventBus;
+ 
+     private static final Logger s_logger = Logger.getLogger(VolumeStateListener.class);
+ 
+     public SnapshotStateListener() {
+ 
+     }
+ 
+     @Override
+     public boolean preStateTransitionEvent(State oldState, Event event, State newState, Snapshot vo, boolean status, Object opaque) {
+         pubishOnEventBus(event.name(), "preStateTransitionEvent", vo, oldState, newState);
+         return true;
+     }
+ 
+     @Override
+     public boolean postStateTransitionEvent(State oldState, Event event, State newState, Snapshot vo, boolean status, Object opaque) {
+         pubishOnEventBus(event.name(), "postStateTransitionEvent", vo, oldState, newState);
+         return true;
+     }
+ 
+     private void pubishOnEventBus(String event, String status, Snapshot vo, State oldState, State newState) {
+ 
+         if (_eventBus == null) {
+             return;  // no provider is configured to provide events bus, so just return
+         }
+ 
+         String resourceName = getEntityFromClassName(Snapshot.class.getName());
+         org.apache.cloudstack.framework.events.Event eventMsg =  new org.apache.cloudstack.framework.events.Event(
+                 ManagementServer.Name,
+                 EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(),
+                 event,
+                 resourceName,
+                 vo.getUuid());
+         Map<String, String> eventDescription = new HashMap<String, String>();
+         eventDescription.put("resource", resourceName);
+         eventDescription.put("id", vo.getUuid());
+         eventDescription.put("old-state", oldState.name());
+         eventDescription.put("new-state", newState.name());
+         eventMsg.setDescription(eventDescription);
+         try {
+             _eventBus.publish(eventMsg);
+         } catch (EventBusException e) {
+             s_logger.warn("Failed to publish state change event on the the event bus.");
+         }
+     }
+ 
+     private String getEntityFromClassName(String entityClassName) {
+         int index = entityClassName.lastIndexOf(".");
+         String entityName = entityClassName;
+         if (index != -1) {
+             entityName = entityClassName.substring(index+1);
+         }
+         return entityName;
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/storage/listener/VolumeStateListener.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/listener/VolumeStateListener.java
index 0000000,177ccf2..ee715e0
mode 000000,100644..100644
--- a/server/src/com/cloud/storage/listener/VolumeStateListener.java
+++ b/server/src/com/cloud/storage/listener/VolumeStateListener.java
@@@ -1,0 -1,102 +1,92 @@@
+ // 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.storage.listener;
+ 
+ import com.cloud.event.EventCategory;
+ import com.cloud.storage.Volume;
+ import com.cloud.storage.Volume.Event;
+ import com.cloud.storage.Volume.State;
+ import com.cloud.server.ManagementServer;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.ComponentLocator;
+ import com.cloud.utils.fsm.StateListener;
+ import org.apache.cloudstack.framework.events.EventBus;
+ import org.apache.cloudstack.framework.events.EventBusException;
+ import org.apache.log4j.Logger;
+ 
 -import java.util.Enumeration;
+ import java.util.HashMap;
+ import java.util.Map;
+ 
++import javax.inject.Inject;
++
+ public class VolumeStateListener implements StateListener<State, Event, Volume> {
+ 
+     // get the event bus provider if configured
 -    protected static EventBus _eventBus = null;
 -    static {
 -        Adapters<EventBus> eventBusImpls = ComponentLocator.getLocator(ManagementServer.Name).getAdapters(EventBus.class);
 -        if (eventBusImpls != null) {
 -            Enumeration<EventBus> eventBusenum = eventBusImpls.enumeration();
 -            if (eventBusenum != null && eventBusenum.hasMoreElements()) {
 -                _eventBus = eventBusenum.nextElement(); // configure event bus if configured
 -            }
 -        }
 -    }
++    @Inject protected EventBus _eventBus = null;
+ 
+     private static final Logger s_logger = Logger.getLogger(VolumeStateListener.class);
+ 
+     public VolumeStateListener() {
+ 
+     }
+ 
+     @Override
+     public boolean preStateTransitionEvent(State oldState, Event event, State newState, Volume vo, boolean status, Object opaque) {
+         pubishOnEventBus(event.name(), "preStateTransitionEvent", vo, oldState, newState);
+         return true;
+     }
+ 
+     @Override
+     public boolean postStateTransitionEvent(State oldState, Event event, State newState, Volume vo, boolean status, Object opaque) {
+         pubishOnEventBus(event.name(), "postStateTransitionEvent", vo, oldState, newState);
+         return true;
+     }
+ 
+     private void pubishOnEventBus(String event, String status, Volume vo, State oldState, State newState) {
+ 
+         if (_eventBus == null) {
+             return;  // no provider is configured to provide events bus, so just return
+         }
+ 
+         String resourceName = getEntityFromClassName(Volume.class.getName());
+         org.apache.cloudstack.framework.events.Event eventMsg =  new org.apache.cloudstack.framework.events.Event(
+                 ManagementServer.Name,
+                 EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(),
+                 event,
+                 resourceName,
+                 vo.getUuid());
+         Map<String, String> eventDescription = new HashMap<String, String>();
+         eventDescription.put("resource", resourceName);
+         eventDescription.put("id", vo.getUuid());
+         eventDescription.put("old-state", oldState.name());
+         eventDescription.put("new-state", newState.name());
+         eventMsg.setDescription(eventDescription);
+         try {
+             _eventBus.publish(eventMsg);
+         } catch (EventBusException e) {
+             s_logger.warn("Failed to state change event on the the event bus.");
+         }
+     }
+ 
+     private String getEntityFromClassName(String entityClassName) {
+         int index = entityClassName.lastIndexOf(".");
+         String entityName = entityClassName;
+         if (index != -1) {
+             entityName = entityClassName.substring(index+1);
+         }
+         return entityName;
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index 4ad43cc,66eb8e1..c7beff0
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@@ -16,33 -16,8 +16,24 @@@
  // under the License.
  package com.cloud.storage.snapshot;
  
 +import java.util.ArrayList;
 +import java.util.Collections;
 +import java.util.Date;
 +import java.util.List;
 +import java.util.Map;
 +import java.util.TimeZone;
 +
 +import javax.ejb.Local;
 +import javax.inject.Inject;
 +import javax.naming.ConfigurationException;
 +
 +import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotPolicyCmd;
 +import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
 +import org.apache.log4j.Logger;
 +import org.springframework.stereotype.Component;
 +
  import com.cloud.agent.AgentManager;
- import com.cloud.agent.api.Answer;
- import com.cloud.agent.api.BackupSnapshotAnswer;
- import com.cloud.agent.api.BackupSnapshotCommand;
- import com.cloud.agent.api.Command;
- import com.cloud.agent.api.DeleteSnapshotBackupCommand;
- import com.cloud.agent.api.DeleteSnapshotsDirCommand;
- import com.cloud.agent.api.DownloadSnapshotFromS3Command;
- import com.cloud.agent.api.ManageSnapshotAnswer;
- import com.cloud.agent.api.ManageSnapshotCommand;
- import com.cloud.agent.api.downloadSnapshotFromSwiftCommand;
+ import com.cloud.agent.api.*;
  import com.cloud.agent.api.to.S3TO;
  import com.cloud.agent.api.to.SwiftTO;
  import com.cloud.alert.AlertManager;
@@@ -115,25 -61,30 +77,37 @@@ import com.cloud.utils.DateUtil.Interva
  import com.cloud.utils.NumbersUtil;
  import com.cloud.utils.Pair;
  import com.cloud.utils.Ternary;
 -import com.cloud.utils.component.ComponentLocator;
 -import com.cloud.utils.component.Inject;
 +
  import com.cloud.utils.component.Manager;
 +import com.cloud.utils.component.ManagerBase;
 +import com.cloud.utils.db.DB;
 +import com.cloud.utils.db.Filter;
 +import com.cloud.utils.db.JoinBuilder;
 +import com.cloud.utils.db.SearchBuilder;
 +import com.cloud.utils.db.SearchCriteria;
 +import com.cloud.utils.db.Transaction;
+ import com.cloud.utils.db.*;
  import com.cloud.utils.exception.CloudRuntimeException;
+ import com.cloud.utils.fsm.NoTransitionException;
+ import com.cloud.utils.fsm.StateMachine2;
  import com.cloud.vm.UserVmVO;
  import com.cloud.vm.VMInstanceVO;
  import com.cloud.vm.VirtualMachine;
  import com.cloud.vm.VirtualMachine.State;
  import com.cloud.vm.dao.UserVmDao;
+ import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotPolicyCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotPoliciesCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
+ import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
+ import org.apache.log4j.Logger;
+ 
+ import javax.ejb.Local;
+ import javax.naming.ConfigurationException;
+ import java.util.*;
  
 +@Component
  @Local(value = { SnapshotManager.class, SnapshotService.class })
 -public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Manager {
 +public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, SnapshotService {
      private static final Logger s_logger = Logger.getLogger(SnapshotManagerImpl.class);
      @Inject
      protected VMTemplateDao _templateDao;
@@@ -293,17 -252,19 +276,19 @@@
              if (preSnapshotPath != null && preSnapshotPath.equals(answer.getSnapshotPath())) {
                  // empty snapshot
                  s_logger.debug("CreateSnapshot: this is empty snapshot ");
+                 try {
 -                    snapshot.setPath(preSnapshotPath);
 -                    snapshot.setBackupSnapshotId(preSnapshotVO.getBackupSnapshotId());
 -                    snapshot.setSwiftId(preSnapshotVO.getSwiftId());
 -                    snapshot.setPrevSnapshotId(preId);
 -                    snapshot.setSecHostId(preSnapshotVO.getSecHostId());
 +                snapshot.setPath(preSnapshotPath);
 +                snapshot.setBackupSnapshotId(preSnapshotVO.getBackupSnapshotId());
 +                snapshot.setSwiftId(preSnapshotVO.getSwiftId());
- 
-                 snapshot.setStatus(Snapshot.Status.BackedUp);
 +                snapshot.setPrevSnapshotId(preId);
 +                snapshot.setSecHostId(preSnapshotVO.getSecHostId());
-                 _snapshotDao.update(snapshotId, snapshot);
+                     stateTransitTo(snapshot, Snapshot.Event.OperationNotPerformed);
+                 }  catch (NoTransitionException nte) {
+                     s_logger.debug("CreateSnapshot: failed to update state of snapshot due to " + nte.getMessage());
+                 }
              } else {
                  long preSnapshotId = 0;
 -
 +               
                  if (preSnapshotVO != null && preSnapshotVO.getBackupSnapshotId() != null) {
                      preSnapshotId = preId;
                      // default delta snap number is 16
@@@ -412,9 -378,9 +402,9 @@@
                          throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " is associated with vm:" + userVm.getInstanceName() + " is in "
                                  + userVm.getState().toString() + " state");
                      }
 -
 +                    
                      if(userVm.getHypervisorType() == HypervisorType.VMware || userVm.getHypervisorType() == HypervisorType.KVM) {
-                         List<SnapshotVO> activeSnapshots = _snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.Status.Creating,  Snapshot.Status.CreatedOnPrimary,  Snapshot.Status.BackingUp);
+                         List<SnapshotVO> activeSnapshots = _snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.State.Creating,  Snapshot.State.CreatedOnPrimary,  Snapshot.State.BackingUp);
                          if(activeSnapshots.size() > 1)
                              throw new CloudRuntimeException("There is other active snapshot tasks on the instance to which the volume is attached, please try again later");
                      }
@@@ -770,8 -737,8 +761,8 @@@
              long oldSnapId = oldestSnapshot.getId();
              s_logger.debug("Max snaps: " + policy.getMaxSnaps() + " exceeded for snapshot policy with Id: " + policyId + ". Deleting oldest snapshot: " + oldSnapId);
              if(deleteSnapshotInternal(oldSnapId)){
 -                //log Snapshot delete event
 +            	//log Snapshot delete event
-             	EventUtils.saveEvent(User.UID_SYSTEM, oldestSnapshot.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_SNAPSHOT_DELETE, "Successfully deleted oldest snapshot: " + oldSnapId, 0);
+                 ActionEventUtils.onCompletedActionEvent(User.UID_SYSTEM, oldestSnapshot.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_SNAPSHOT_DELETE, "Successfully deleted oldest snapshot: " + oldSnapId, 0);
              }
              snaps.remove(oldestSnapshot);
          }
@@@ -788,13 -755,13 +779,13 @@@
          if (snapshotCheck == null) {
              throw new InvalidParameterValueException("unable to find a snapshot with id " + snapshotId);
          }
 -
 +        
          _accountMgr.checkAccess(caller, null, true, snapshotCheck);
 -
 +        
-         if( !Status.BackedUp.equals(snapshotCheck.getStatus() ) ) {
+         if( !Snapshot.State.BackedUp.equals(snapshotCheck.getState() ) ) {
              throw new InvalidParameterValueException("Can't delete snapshotshot " + snapshotId + " due to it is not in BackedUp Status");
          }
 -
 +        
          return deleteSnapshotInternal(snapshotId);
      }
  
@@@ -1526,10 -1510,11 +1521,11 @@@
          }
          return false;
      }
 -
 +    
      @Override
      public boolean canOperateOnVolume(VolumeVO volume) {
-     	List<SnapshotVO> snapshots = _snapshotDao.listByStatus(volume.getId(), Status.Creating, Status.CreatedOnPrimary, Status.BackingUp);
+         List<SnapshotVO> snapshots = _snapshotDao.listByStatus(volume.getId(), Snapshot.State.Creating,
+                 Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp);
      	if (snapshots.size() > 0) {
      		return false;
      	}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
index cbd2933,9389893..5af0af0
--- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
@@@ -24,12 -24,11 +24,13 @@@ import java.util.Timer
  import java.util.TimerTask;
  
  import javax.ejb.Local;
 +import javax.inject.Inject;
  import javax.naming.ConfigurationException;
  
+ import com.cloud.event.ActionEventUtils;
  import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotCmd;
  import org.apache.log4j.Logger;
 +import org.springframework.stereotype.Component;
  
  import org.apache.cloudstack.api.ApiConstants;
  import com.cloud.api.ApiDispatcher;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/template/HyervisorTemplateAdapter.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/template/HyervisorTemplateAdapter.java
index 732b153,81a482b..089f650
--- a/server/src/com/cloud/template/HyervisorTemplateAdapter.java
+++ b/server/src/com/cloud/template/HyervisorTemplateAdapter.java
@@@ -53,10 -35,19 +51,19 @@@ import com.cloud.storage.VMTemplateZone
  import com.cloud.storage.download.DownloadMonitor;
  import com.cloud.storage.secondary.SecondaryStorageVmManager;
  import com.cloud.user.Account;
 -import com.cloud.utils.component.Inject;
  import com.cloud.utils.db.DB;
  import com.cloud.utils.exception.CloudRuntimeException;
+ import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
+ import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
+ import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
+ import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
+ import org.apache.log4j.Logger;
+ 
+ import javax.ejb.Local;
+ import java.net.*;
+ import java.util.List;
  
 +@Component
  @Local(value=TemplateAdapter.class)
  public class HyervisorTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter {
  	private final static Logger s_logger = Logger.getLogger(HyervisorTemplateAdapter.class);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/template/TemplateManagerImpl.java
index 0a46414,42106b3..f9cf277
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@@ -79,40 -50,12 +77,19 @@@ import com.cloud.hypervisor.Hypervisor.
  import com.cloud.hypervisor.HypervisorGuruManager;
  import com.cloud.projects.Project;
  import com.cloud.projects.ProjectManager;
- import com.cloud.storage.LaunchPermissionVO;
- import com.cloud.storage.SnapshotVO;
- import com.cloud.storage.Storage;
+ import com.cloud.storage.*;
  import com.cloud.storage.Storage.ImageFormat;
  import com.cloud.storage.Storage.TemplateType;
 +import com.cloud.storage.StorageManager;
 +import com.cloud.storage.StoragePool;
 +import com.cloud.storage.StoragePoolHostVO;
 +import com.cloud.storage.StoragePoolStatus;
 +import com.cloud.storage.StoragePoolVO;
 +import com.cloud.storage.TemplateProfile;
 +import com.cloud.storage.Upload;
  import com.cloud.storage.Upload.Type;
- import com.cloud.storage.UploadVO;
- import com.cloud.storage.VMTemplateHostVO;
- import com.cloud.storage.VMTemplateStoragePoolVO;
- import com.cloud.storage.VMTemplateStorageResourceAssoc;
  import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
- import com.cloud.storage.VMTemplateSwiftVO;
- import com.cloud.storage.VMTemplateVO;
- import com.cloud.storage.VMTemplateZoneVO;
- import com.cloud.storage.VolumeVO;
- import com.cloud.storage.dao.LaunchPermissionDao;
- import com.cloud.storage.dao.SnapshotDao;
- import com.cloud.storage.dao.StoragePoolDao;
- import com.cloud.storage.dao.StoragePoolHostDao;
- import com.cloud.storage.dao.UploadDao;
- import com.cloud.storage.dao.VMTemplateDao;
- import com.cloud.storage.dao.VMTemplateHostDao;
- import com.cloud.storage.dao.VMTemplatePoolDao;
- import com.cloud.storage.dao.VMTemplateS3Dao;
- import com.cloud.storage.dao.VMTemplateSwiftDao;
- import com.cloud.storage.dao.VMTemplateZoneDao;
- import com.cloud.storage.dao.VolumeDao;
+ import com.cloud.storage.dao.*;
  import com.cloud.storage.download.DownloadMonitor;
  import com.cloud.storage.s3.S3Manager;
  import com.cloud.storage.secondary.SecondaryStorageVmManager;
@@@ -130,17 -68,12 +102,11 @@@ import com.cloud.user.dao.UserAccountDa
  import com.cloud.user.dao.UserDao;
  import com.cloud.uservm.UserVm;
  import com.cloud.utils.NumbersUtil;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.ComponentLocator;
 -import com.cloud.utils.component.Inject;
 -import com.cloud.utils.component.Manager;
 +import com.cloud.utils.component.AdapterBase;
 +import com.cloud.utils.component.ManagerBase;
 +
- import com.cloud.utils.component.Manager;
  import com.cloud.utils.concurrency.NamedThreadFactory;
- import com.cloud.utils.db.DB;
- import com.cloud.utils.db.GlobalLock;
- import com.cloud.utils.db.JoinBuilder;
- import com.cloud.utils.db.SearchBuilder;
- import com.cloud.utils.db.SearchCriteria;
- import com.cloud.utils.db.Transaction;
+ import com.cloud.utils.db.*;
  import com.cloud.utils.exception.CloudRuntimeException;
  import com.cloud.vm.UserVmManager;
  import com.cloud.vm.UserVmVO;


Mime
View raw message