mirror of https://github.com/apache/cloudstack.git
ProvisioningService:: registerZone changes and unit-test
This commit is contained in:
parent
d7bc09f950
commit
1eb64e6181
|
|
@ -19,6 +19,8 @@
|
|||
package org.apache.cloudstack.engine.datacenter.entity.api;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
|
||||
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
|
|
@ -90,8 +92,11 @@ public interface DataCenterResourceEntity extends CloudStackEntity, StateObject<
|
|||
@POST
|
||||
boolean reactivate();
|
||||
|
||||
|
||||
@Override
|
||||
@GET
|
||||
State getState();
|
||||
|
||||
|
||||
public void persist();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,10 +25,6 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.Produces;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.apache.cloudstack.engine.service.api.ProvisioningService;
|
||||
import org.apache.cloudstack.framework.ws.jackson.Url;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
|
||||
/**
|
||||
* Describes a zone and operations that can be done in a zone.
|
||||
|
|
@ -36,7 +32,8 @@ import com.cloud.dc.DataCenter;
|
|||
@Path("/zone/{zoneid}")
|
||||
@Produces({"application/json"})
|
||||
@XmlRootElement(name="zone")
|
||||
public interface ZoneEntity extends DataCenterResourceEntity, DataCenter {
|
||||
@Path("zone/{zone-id}")
|
||||
public interface ZoneEntity extends DataCenterResourceEntity {
|
||||
@GET
|
||||
@Path("/pods")
|
||||
List<PodEntity> listPods();
|
||||
|
|
|
|||
|
|
@ -80,19 +80,13 @@ public interface CloudStackEntity {
|
|||
/**
|
||||
* @return details stored for this entity when created.
|
||||
*/
|
||||
Map<String, String> getDetails(
|
||||
@QueryParam("source") String source);
|
||||
Map<String, String> getDetails();
|
||||
|
||||
/**
|
||||
* @return a list of sources that have added to the details.
|
||||
*/
|
||||
List<String> getDetailSources();
|
||||
void addDetail(String name, String value);
|
||||
|
||||
void addDetail(String source, String name, String value);
|
||||
void delDetail(String name, String value);
|
||||
|
||||
void delDetail(String source, String name, String value);
|
||||
|
||||
void updateDetail(String source, String name, String value);
|
||||
void updateDetail(String name, String value);
|
||||
|
||||
/**
|
||||
* @return list of actions that can be performed on the object in its current state
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ package org.apache.cloudstack.engine.service.api;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.POST;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
|
||||
|
|
@ -39,9 +41,11 @@ public interface ProvisioningService {
|
|||
|
||||
StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details);
|
||||
|
||||
ZoneEntity registerZone(String name, List<String> tags, Map<String, String> details);
|
||||
@POST
|
||||
ZoneEntity registerZone(String zoneUuid, String owner, List<String> tags, Map<String, String> details);
|
||||
|
||||
PodEntity registerPod(String name, List<String> tags, Map<String, String> details);
|
||||
@POST
|
||||
PodEntity registerPod(String name, Long zoneId, String gateway, String cidr, String startIp, String endIp, List<String> tags, Map<String, String> details);
|
||||
|
||||
ClusterEntity registerCluster(String name, List<String> tags, Map<String, String> details);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,21 @@
|
|||
<artifactId>cloud-engine-components-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package org.apache.cloudstack.engine.datacenter.entity.api;
|
||||
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
|
||||
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
|
||||
|
||||
public interface DataCenterResourceManager {
|
||||
|
||||
DataCenterVO loadDataCenter(String dataCenterId);
|
||||
|
||||
void saveDataCenter(DataCenterVO dc);
|
||||
|
||||
boolean changeState(ZoneEntity dc, Event event) throws NoTransitionException;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package org.apache.cloudstack.engine.datacenter.entity.api;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
import com.cloud.utils.fsm.StateMachine2;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
@Component
|
||||
public class DataCenterResourceManagerImpl implements DataCenterResourceManager {
|
||||
|
||||
// @Inject
|
||||
DataCenterDao _dataCenterDao;
|
||||
|
||||
protected StateMachine2<State, Event, DataCenterResourceEntity> _stateMachine;
|
||||
|
||||
@Override
|
||||
public DataCenterVO loadDataCenter(String dataCenterId) {
|
||||
DataCenterVO dataCenterVO = _dataCenterDao.findByUUID(dataCenterId);
|
||||
if(dataCenterVO == null){
|
||||
throw new InvalidParameterValueException("Zone does not exist");
|
||||
}
|
||||
return dataCenterVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDataCenter(DataCenterVO dc) {
|
||||
_dataCenterDao.persist(dc);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean changeState(ZoneEntity entity, Event event) throws NoTransitionException {
|
||||
return _stateMachine.transitTo((DataCenterResourceEntity)entity, event, null, _dataCenterDao);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -105,35 +105,6 @@ public class PodEntityImpl implements PodEntity {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails(String source) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDetailSources() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Method> getApplicableActions() {
|
||||
|
|
@ -194,4 +165,34 @@ public class PodEntityImpl implements PodEntity {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persist() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,53 +24,86 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
public class ZoneEntityImpl implements ZoneEntity {
|
||||
String _id;
|
||||
String _name;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao;
|
||||
import org.apache.cloudstack.engine.service.api.ProvisioningService;
|
||||
|
||||
// This is a test constructor
|
||||
public ZoneEntityImpl(String id, String name) {
|
||||
_id = id;
|
||||
_name = name;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.fsm.FiniteStateObject;
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
|
||||
@Component
|
||||
@Path("/zone/{id}")
|
||||
public class ZoneEntityImpl implements ZoneEntity, FiniteStateObject<DataCenterResourceEntity.State, DataCenterResourceEntity.State.Event> {
|
||||
|
||||
@Inject
|
||||
DataCenterResourceManager manager;
|
||||
|
||||
|
||||
private DataCenterVO dataCenterVO;
|
||||
|
||||
|
||||
public ZoneEntityImpl(String dataCenterId) {
|
||||
this.dataCenterVO = manager.loadDataCenter(dataCenterId);
|
||||
}
|
||||
|
||||
public ZoneEntityImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enable() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disable() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deactivate() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reactivate() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
@GET
|
||||
public String getUuid() {
|
||||
return _id;
|
||||
return dataCenterVO.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return dataCenterVO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enable() {
|
||||
try {
|
||||
manager.changeState(this, Event.EnableRequest);
|
||||
} catch (NoTransitionException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disable() {
|
||||
try {
|
||||
manager.changeState(this, Event.DisableRequest);
|
||||
} catch (NoTransitionException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deactivate() {
|
||||
try {
|
||||
manager.changeState(this, Event.DeactivateRequest);
|
||||
} catch (NoTransitionException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reactivate() {
|
||||
try {
|
||||
manager.changeState(this, Event.ActivatedRequest);
|
||||
} catch (NoTransitionException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -87,48 +120,45 @@ public class ZoneEntityImpl implements ZoneEntity {
|
|||
|
||||
@Override
|
||||
public Date getCreatedTime() {
|
||||
// TODO Auto-generated method stub
|
||||
return new Date();
|
||||
return dataCenterVO.getCreated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastUpdatedTime() {
|
||||
// TODO Auto-generated method stub
|
||||
return new Date();
|
||||
return dataCenterVO.getLastUpdated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner() {
|
||||
// TODO Auto-generated method stub
|
||||
return "owner";
|
||||
return dataCenterVO.getOwner();
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
dataCenterVO.setOwner(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails() {
|
||||
return dataCenterVO.getDetails();
|
||||
}
|
||||
|
||||
public void setDetails(Map<String,String> details) {
|
||||
dataCenterVO.setDetails(details);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addDetail(String name, String value) {
|
||||
dataCenterVO.setDetail(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails(String source) {
|
||||
public void delDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDetailSources() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String source, String name, String value) {
|
||||
public void updateDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
@ -141,146 +171,9 @@ public class ZoneEntityImpl implements ZoneEntity {
|
|||
|
||||
@Override
|
||||
public State getState() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return dataCenterVO.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDns1() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDns2() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuestNetworkCidr() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDomainId() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDomain() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkType getNetworkType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalDns1() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalDns2() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDnsProvider() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGatewayProvider() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirewallProvider() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDhcpProvider() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoadBalancerProvider() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserDataProvider() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVpnProvider() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecurityGroupEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDetails(Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllocationState getAllocationState() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getZoneToken() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocalStorageEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PodEntity> listPods() {
|
||||
|
|
@ -288,6 +181,17 @@ public class ZoneEntityImpl implements ZoneEntity {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(State state) {
|
||||
//use FSM to set state.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persist() {
|
||||
manager.saveDataCenter(dataCenterVO);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> listPodIds() {
|
||||
List<String> podIds = new ArrayList<String>();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by 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.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package org.apache.cloudstack.engine.datacenter.entity.api.db;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="cluster_details")
|
||||
public class ClusterDetailsVO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private long id;
|
||||
|
||||
@Column(name="cluster_id")
|
||||
private long clusterId;
|
||||
|
||||
@Column(name="name")
|
||||
private String name;
|
||||
|
||||
@Column(name="value")
|
||||
private String value;
|
||||
|
||||
protected ClusterDetailsVO() {
|
||||
}
|
||||
|
||||
public ClusterDetailsVO(long clusterId, String name, String value) {
|
||||
this.clusterId = clusterId;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getClusterId() {
|
||||
return clusterId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,478 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by 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.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package org.apache.cloudstack.engine.datacenter.entity.api.db;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
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 javax.persistence.TableGenerator;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
|
||||
|
||||
import com.cloud.api.Identity;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.org.Grouping;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.db.StateMachine;
|
||||
|
||||
@Entity
|
||||
@Table(name="data_center")
|
||||
public class DataCenterVO implements DataCenter, Identity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private long id;
|
||||
|
||||
@Column(name="name")
|
||||
private String name = null;
|
||||
|
||||
@Column(name="description")
|
||||
private String description = null;
|
||||
|
||||
@Column(name="dns1")
|
||||
private String dns1 = null;
|
||||
|
||||
@Column(name="dns2")
|
||||
private String dns2 = null;
|
||||
|
||||
@Column(name="internal_dns1")
|
||||
private String internalDns1 = null;
|
||||
|
||||
@Column(name="internal_dns2")
|
||||
private String internalDns2 = null;
|
||||
|
||||
@Column(name="router_mac_address", updatable = false, nullable=false)
|
||||
private String routerMacAddress = "02:00:00:00:00:01";
|
||||
|
||||
@Column(name="guest_network_cidr")
|
||||
private String guestNetworkCidr = null;
|
||||
|
||||
@Column(name="domain_id")
|
||||
private Long domainId = null;
|
||||
|
||||
@Column(name="domain")
|
||||
private String domain;
|
||||
|
||||
@Column(name="networktype")
|
||||
@Enumerated(EnumType.STRING)
|
||||
NetworkType networkType;
|
||||
|
||||
@Column(name="dns_provider")
|
||||
private String dnsProvider;
|
||||
|
||||
@Column(name="dhcp_provider")
|
||||
private String dhcpProvider;
|
||||
|
||||
@Column(name="gateway_provider")
|
||||
private String gatewayProvider;
|
||||
|
||||
@Column(name="vpn_provider")
|
||||
private String vpnProvider;
|
||||
|
||||
@Column(name="userdata_provider")
|
||||
private String userDataProvider;
|
||||
|
||||
@Column(name="lb_provider")
|
||||
private String loadBalancerProvider;
|
||||
|
||||
@Column(name="firewall_provider")
|
||||
private String firewallProvider;
|
||||
|
||||
@Column(name="mac_address", nullable=false)
|
||||
@TableGenerator(name="mac_address_sq", table="data_center", pkColumnName="id", valueColumnName="mac_address", allocationSize=1)
|
||||
private long macAddress = 1;
|
||||
|
||||
@Column(name="zone_token")
|
||||
private String zoneToken;
|
||||
|
||||
@Column(name=GenericDao.REMOVED_COLUMN)
|
||||
private Date removed;
|
||||
|
||||
// This is a delayed load value. If the value is null,
|
||||
// then this field has not been loaded yet.
|
||||
// Call the dao to load it.
|
||||
@Transient
|
||||
Map<String, String> details;
|
||||
|
||||
@Column(name="allocation_state")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
AllocationState allocationState;
|
||||
|
||||
@Column(name="uuid")
|
||||
private String uuid;
|
||||
|
||||
@Column(name="is_security_group_enabled")
|
||||
boolean securityGroupEnabled;
|
||||
|
||||
@Column(name="is_local_storage_enabled")
|
||||
boolean localStorageEnabled;
|
||||
|
||||
//orchestration
|
||||
@Column(name="owner")
|
||||
private String owner = null;
|
||||
|
||||
@Column(name=GenericDao.CREATED_COLUMN)
|
||||
protected Date created;
|
||||
|
||||
@Column(name="lastUpdated", updatable=true)
|
||||
@Temporal(value=TemporalType.TIMESTAMP)
|
||||
protected Date lastUpdated;
|
||||
|
||||
/**
|
||||
* Note that state is intentionally missing the setter. Any updates to
|
||||
* the state machine needs to go through the DAO object because someone
|
||||
* else could be updating it as well.
|
||||
*/
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@StateMachine(state=State.class, event=Event.class)
|
||||
@Column(name="state", updatable=true, nullable=false, length=32)
|
||||
protected State state = null;
|
||||
|
||||
|
||||
@Override
|
||||
public String getDnsProvider() {
|
||||
return dnsProvider;
|
||||
}
|
||||
|
||||
public void setDnsProvider(String dnsProvider) {
|
||||
this.dnsProvider = dnsProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDhcpProvider() {
|
||||
return dhcpProvider;
|
||||
}
|
||||
|
||||
public void setDhcpProvider(String dhcpProvider) {
|
||||
this.dhcpProvider = dhcpProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGatewayProvider() {
|
||||
return gatewayProvider;
|
||||
}
|
||||
|
||||
public void setGatewayProvider(String gatewayProvider) {
|
||||
this.gatewayProvider = gatewayProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoadBalancerProvider() {
|
||||
return loadBalancerProvider;
|
||||
}
|
||||
|
||||
public void setLoadBalancerProvider(String loadBalancerProvider) {
|
||||
this.loadBalancerProvider = loadBalancerProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirewallProvider() {
|
||||
return firewallProvider;
|
||||
}
|
||||
|
||||
public void setFirewallProvider(String firewallProvider) {
|
||||
this.firewallProvider = firewallProvider;
|
||||
}
|
||||
|
||||
public DataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix) {
|
||||
this(name, description, dns1, dns2, dns3, dns4, guestCidr, domain, domainId, zoneType, zoneToken, domainSuffix, false, false);
|
||||
this.id = id;
|
||||
this.allocationState = Grouping.AllocationState.Enabled;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String guestCidr, String domain, Long domainId, NetworkType zoneType, String zoneToken, String domainSuffix, boolean securityGroupEnabled, boolean localStorageEnabled) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.dns1 = dns1;
|
||||
this.dns2 = dns2;
|
||||
this.internalDns1 = dns3;
|
||||
this.internalDns2 = dns4;
|
||||
this.guestNetworkCidr = guestCidr;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.networkType = zoneType;
|
||||
this.allocationState = Grouping.AllocationState.Enabled;
|
||||
this.securityGroupEnabled = securityGroupEnabled;
|
||||
this.localStorageEnabled = localStorageEnabled;
|
||||
|
||||
if (zoneType == NetworkType.Advanced) {
|
||||
loadBalancerProvider = Provider.VirtualRouter.getName();
|
||||
firewallProvider = Provider.VirtualRouter.getName();
|
||||
dhcpProvider = Provider.VirtualRouter.getName();
|
||||
dnsProvider = Provider.VirtualRouter.getName();
|
||||
gatewayProvider = Provider.VirtualRouter.getName();
|
||||
vpnProvider = Provider.VirtualRouter.getName();
|
||||
userDataProvider = Provider.VirtualRouter.getName();
|
||||
} else if (zoneType == NetworkType.Basic){
|
||||
dhcpProvider = Provider.VirtualRouter.getName();
|
||||
dnsProvider = Provider.VirtualRouter.getName();
|
||||
userDataProvider = Provider.VirtualRouter.getName();
|
||||
loadBalancerProvider = Provider.ElasticLoadBalancerVm.getName();
|
||||
}
|
||||
|
||||
this.zoneToken = zoneToken;
|
||||
this.domain = domainSuffix;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVpnProvider() {
|
||||
return vpnProvider;
|
||||
}
|
||||
|
||||
public void setVpnProvider(String vpnProvider) {
|
||||
this.vpnProvider = vpnProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserDataProvider() {
|
||||
return userDataProvider;
|
||||
}
|
||||
|
||||
public void setUserDataProvider(String userDataProvider) {
|
||||
this.userDataProvider = userDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuestNetworkCidr()
|
||||
{
|
||||
return guestNetworkCidr;
|
||||
}
|
||||
|
||||
public void setGuestNetworkCidr(String guestNetworkCidr)
|
||||
{
|
||||
this.guestNetworkCidr = guestNetworkCidr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getRouterMacAddress() {
|
||||
return routerMacAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDns1() {
|
||||
return dns1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDns2() {
|
||||
return dns2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalDns1() {
|
||||
return internalDns1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInternalDns2() {
|
||||
return internalDns2;
|
||||
}
|
||||
|
||||
protected DataCenterVO() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDns1(String dns1) {
|
||||
this.dns1 = dns1;
|
||||
}
|
||||
|
||||
public void setDns2(String dns2) {
|
||||
this.dns2 = dns2;
|
||||
}
|
||||
|
||||
public void setInternalDns1(String dns3) {
|
||||
this.internalDns1 = dns3;
|
||||
}
|
||||
|
||||
public void setInternalDns2(String dns4) {
|
||||
this.internalDns2 = dns4;
|
||||
}
|
||||
|
||||
public void setRouterMacAddress(String routerMacAddress) {
|
||||
this.routerMacAddress = routerMacAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public void setNetworkType(NetworkType zoneNetworkType) {
|
||||
this.networkType = zoneNetworkType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkType getNetworkType() {
|
||||
return networkType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecurityGroupEnabled() {
|
||||
return securityGroupEnabled;
|
||||
}
|
||||
|
||||
public void setSecurityGroupEnabled(boolean enabled) {
|
||||
this.securityGroupEnabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocalStorageEnabled() {
|
||||
return localStorageEnabled;
|
||||
}
|
||||
|
||||
public void setLocalStorageEnabled(boolean enabled) {
|
||||
this.localStorageEnabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails() {
|
||||
return details;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDetails(Map<String, String> details2) {
|
||||
details = details2;
|
||||
}
|
||||
|
||||
public String getDetail(String name) {
|
||||
assert (details != null) : "Did you forget to load the details?";
|
||||
|
||||
return details != null ? details.get(name) : null;
|
||||
}
|
||||
|
||||
public void setDetail(String name, String value) {
|
||||
assert (details != null) : "Did you forget to load the details?";
|
||||
|
||||
details.put(name, value);
|
||||
}
|
||||
|
||||
public AllocationState getAllocationState() {
|
||||
return allocationState;
|
||||
}
|
||||
|
||||
public void setAllocationState(AllocationState allocationState) {
|
||||
this.allocationState = allocationState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return NumbersUtil.hash(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof DataCenterVO)) {
|
||||
return false;
|
||||
}
|
||||
DataCenterVO that = (DataCenterVO)obj;
|
||||
return this.id == that.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getZoneToken() {
|
||||
return zoneToken;
|
||||
}
|
||||
|
||||
public void setZoneToken(String zoneToken) {
|
||||
this.zoneToken = zoneToken;
|
||||
}
|
||||
|
||||
public Date getRemoved() {
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public long getMacAddress() {
|
||||
return macAddress;
|
||||
}
|
||||
|
||||
public void setMacAddress(long macAddress) {
|
||||
this.macAddress = macAddress;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public Date getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by 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.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package org.apache.cloudstack.engine.datacenter.entity.api.db;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="data_center_details")
|
||||
public class DcDetailVO {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private long id;
|
||||
|
||||
@Column(name="dc_id")
|
||||
private long dcId;
|
||||
|
||||
@Column(name="name")
|
||||
private String name;
|
||||
|
||||
@Column(name="value")
|
||||
private String value;
|
||||
|
||||
protected DcDetailVO() {
|
||||
}
|
||||
|
||||
public DcDetailVO(long dcId, String name, String value) {
|
||||
this.dcId = dcId;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getDcId() {
|
||||
return dcId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by 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.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.fsm.StateDao;
|
||||
|
||||
|
||||
public interface DataCenterDao extends GenericDao<DataCenterVO, Long>, StateDao<DataCenterResourceEntity.State, DataCenterResourceEntity.State.Event, DataCenterResourceEntity> {
|
||||
DataCenterVO findByName(String name);
|
||||
|
||||
/**
|
||||
* @param id data center id
|
||||
* @return a pair of mac address strings. The first one is private and second is public.
|
||||
*/
|
||||
String[] getNextAvailableMacAddressPair(long id);
|
||||
String[] getNextAvailableMacAddressPair(long id, long mask);
|
||||
List<DataCenterVO> findZonesByDomainId(Long domainId);
|
||||
|
||||
List<DataCenterVO> listPublicZones(String keyword);
|
||||
|
||||
List<DataCenterVO> findChildZones(Object[] ids, String keyword);
|
||||
|
||||
void loadDetails(DataCenterVO zone);
|
||||
void saveDetails(DataCenterVO zone);
|
||||
|
||||
List<DataCenterVO> listDisabledZones();
|
||||
List<DataCenterVO> listEnabledZones();
|
||||
DataCenterVO findByToken(String zoneToken);
|
||||
DataCenterVO findByTokenOrIdOrName(String tokenIdOrName);
|
||||
|
||||
|
||||
|
||||
List<DataCenterVO> findZonesByDomainId(Long domainId, String keyword);
|
||||
|
||||
List<DataCenterVO> findByKeyword(String keyword);
|
||||
|
||||
DataCenterVO findByUUID(String uuid);
|
||||
}
|
||||
|
|
@ -0,0 +1,333 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by 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.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.org.Grouping;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SequenceFetcher;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
/**
|
||||
* @config
|
||||
* {@table
|
||||
* || Param Name | Description | Values | Default ||
|
||||
* || mac.address.prefix | prefix to attach to all public and private mac addresses | number | 06 ||
|
||||
* }
|
||||
**/
|
||||
@Local(value={DataCenterDao.class})
|
||||
public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implements DataCenterDao {
|
||||
private static final Logger s_logger = Logger.getLogger(DataCenterDaoImpl.class);
|
||||
|
||||
protected SearchBuilder<DataCenterVO> NameSearch;
|
||||
protected SearchBuilder<DataCenterVO> ListZonesByDomainIdSearch;
|
||||
protected SearchBuilder<DataCenterVO> PublicZonesSearch;
|
||||
protected SearchBuilder<DataCenterVO> ChildZonesSearch;
|
||||
protected SearchBuilder<DataCenterVO> DisabledZonesSearch;
|
||||
protected SearchBuilder<DataCenterVO> TokenSearch;
|
||||
protected SearchBuilder<DataCenterVO> StateChangeSearch;
|
||||
protected SearchBuilder<DataCenterVO> UUIDSearch;
|
||||
|
||||
protected long _prefix;
|
||||
protected Random _rand = new Random(System.currentTimeMillis());
|
||||
protected TableGenerator _tgMacAddress;
|
||||
|
||||
protected final DcDetailsDaoImpl _detailsDao = ComponentLocator.inject(DcDetailsDaoImpl.class);
|
||||
|
||||
|
||||
@Override
|
||||
public DataCenterVO findByName(String name) {
|
||||
SearchCriteria<DataCenterVO> sc = NameSearch.create();
|
||||
sc.setParameters("name", name);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataCenterVO findByUUID(String uuid) {
|
||||
SearchCriteria<DataCenterVO> sc = UUIDSearch.create();
|
||||
sc.setParameters("uuid", uuid);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataCenterVO findByToken(String zoneToken){
|
||||
SearchCriteria<DataCenterVO> sc = TokenSearch.create();
|
||||
sc.setParameters("zoneToken", zoneToken);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataCenterVO> findZonesByDomainId(Long domainId){
|
||||
SearchCriteria<DataCenterVO> sc = ListZonesByDomainIdSearch.create();
|
||||
sc.setParameters("domainId", domainId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataCenterVO> findZonesByDomainId(Long domainId, String keyword){
|
||||
SearchCriteria<DataCenterVO> sc = ListZonesByDomainIdSearch.create();
|
||||
sc.setParameters("domainId", domainId);
|
||||
if (keyword != null) {
|
||||
SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataCenterVO> findChildZones(Object[] ids, String keyword){
|
||||
SearchCriteria<DataCenterVO> sc = ChildZonesSearch.create();
|
||||
sc.setParameters("domainid", ids);
|
||||
if (keyword != null) {
|
||||
SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataCenterVO> listPublicZones(String keyword){
|
||||
SearchCriteria<DataCenterVO> sc = PublicZonesSearch.create();
|
||||
if (keyword != null) {
|
||||
SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
//sc.setParameters("domainId", domainId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataCenterVO> findByKeyword(String keyword){
|
||||
SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
return listBy(ssc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getNextAvailableMacAddressPair(long id) {
|
||||
return getNextAvailableMacAddressPair(id, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNextAvailableMacAddressPair(long id, long mask) {
|
||||
SequenceFetcher fetch = SequenceFetcher.getInstance();
|
||||
|
||||
long seq = fetch.getNextSequence(Long.class, _tgMacAddress, id);
|
||||
seq = seq | _prefix | ((id & 0x7f) << 32);
|
||||
seq |= mask;
|
||||
seq |= ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l);
|
||||
String[] pair = new String[2];
|
||||
pair[0] = NetUtils.long2Mac(seq);
|
||||
pair[1] = NetUtils.long2Mac(seq | 0x1l << 39);
|
||||
return pair;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
if (!super.configure(name, params)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String value = (String)params.get("mac.address.prefix");
|
||||
_prefix = (long)NumbersUtil.parseInt(value, 06) << 40;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected DataCenterDaoImpl() {
|
||||
super();
|
||||
NameSearch = createSearchBuilder();
|
||||
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||
NameSearch.done();
|
||||
|
||||
ListZonesByDomainIdSearch = createSearchBuilder();
|
||||
ListZonesByDomainIdSearch.and("domainId", ListZonesByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
ListZonesByDomainIdSearch.done();
|
||||
|
||||
PublicZonesSearch = createSearchBuilder();
|
||||
PublicZonesSearch.and("domainId", PublicZonesSearch.entity().getDomainId(), SearchCriteria.Op.NULL);
|
||||
PublicZonesSearch.done();
|
||||
|
||||
ChildZonesSearch = createSearchBuilder();
|
||||
ChildZonesSearch.and("domainid", ChildZonesSearch.entity().getDomainId(), SearchCriteria.Op.IN);
|
||||
ChildZonesSearch.done();
|
||||
|
||||
DisabledZonesSearch = createSearchBuilder();
|
||||
DisabledZonesSearch.and("allocationState", DisabledZonesSearch.entity().getAllocationState(), SearchCriteria.Op.EQ);
|
||||
DisabledZonesSearch.done();
|
||||
|
||||
TokenSearch = createSearchBuilder();
|
||||
TokenSearch.and("zoneToken", TokenSearch.entity().getZoneToken(), SearchCriteria.Op.EQ);
|
||||
TokenSearch.done();
|
||||
|
||||
StateChangeSearch = createSearchBuilder();
|
||||
StateChangeSearch.and("id", StateChangeSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
StateChangeSearch.and("state", StateChangeSearch.entity().getState(), SearchCriteria.Op.EQ);
|
||||
StateChangeSearch.done();
|
||||
|
||||
UUIDSearch = createSearchBuilder();
|
||||
UUIDSearch.and("uuid", UUIDSearch.entity().getUuid(), SearchCriteria.Op.EQ);
|
||||
UUIDSearch.done();
|
||||
|
||||
|
||||
_tgMacAddress = _tgs.get("macAddress");
|
||||
assert _tgMacAddress != null : "Couldn't get mac address table generator";
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public boolean update(Long zoneId, DataCenterVO zone) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
boolean persisted = super.update(zoneId, zone);
|
||||
if (!persisted) {
|
||||
return persisted;
|
||||
}
|
||||
saveDetails(zone);
|
||||
txn.commit();
|
||||
return persisted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDetails(DataCenterVO zone) {
|
||||
Map<String, String> details =_detailsDao.findDetails(zone.getId());
|
||||
zone.setDetails(details);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDetails(DataCenterVO zone) {
|
||||
Map<String, String> details = zone.getDetails();
|
||||
if (details == null) {
|
||||
return;
|
||||
}
|
||||
_detailsDao.persist(zone.getId(), details);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataCenterVO> listDisabledZones(){
|
||||
SearchCriteria<DataCenterVO> sc = DisabledZonesSearch.create();
|
||||
sc.setParameters("allocationState", Grouping.AllocationState.Disabled);
|
||||
|
||||
List<DataCenterVO> dcs = listBy(sc);
|
||||
|
||||
return dcs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataCenterVO> listEnabledZones(){
|
||||
SearchCriteria<DataCenterVO> sc = DisabledZonesSearch.create();
|
||||
sc.setParameters("allocationState", Grouping.AllocationState.Enabled);
|
||||
|
||||
List<DataCenterVO> dcs = listBy(sc);
|
||||
|
||||
return dcs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataCenterVO findByTokenOrIdOrName(String tokenOrIdOrName) {
|
||||
DataCenterVO result = findByToken(tokenOrIdOrName);
|
||||
if (result == null) {
|
||||
result = findByName(tokenOrIdOrName);
|
||||
if (result == null) {
|
||||
try {
|
||||
Long dcId = Long.parseLong(tokenOrIdOrName);
|
||||
return findById(dcId);
|
||||
} catch (NumberFormatException nfe) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Long id) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
DataCenterVO zone = createForUpdate();
|
||||
zone.setName(null);
|
||||
|
||||
update(id, zone);
|
||||
|
||||
boolean result = super.remove(id);
|
||||
txn.commit();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity zoneEntity, Object data) {
|
||||
|
||||
DataCenterVO vo = findById(zoneEntity.getId());
|
||||
|
||||
Date oldUpdatedTime = vo.getLastUpdated();
|
||||
|
||||
SearchCriteria<DataCenterVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", vo.getId());
|
||||
sc.setParameters("state", currentState);
|
||||
|
||||
UpdateBuilder builder = getUpdateBuilder(vo);
|
||||
builder.set(vo, "state", nextState);
|
||||
builder.set(vo, "lastUpdated", new Date());
|
||||
|
||||
int rows = update((DataCenterVO) vo, sc);
|
||||
|
||||
if (rows == 0 && s_logger.isDebugEnabled()) {
|
||||
DataCenterVO dbDC = findByIdIncludingRemoved(vo.getId());
|
||||
if (dbDC != null) {
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={id=").append(dbDC.getId()).append("; state=").append(dbDC.getState()).append(";updatedTime=")
|
||||
.append(dbDC.getLastUpdated());
|
||||
str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatedTime=").append(vo.getLastUpdated());
|
||||
str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatedTime=").append(oldUpdatedTime);
|
||||
} else {
|
||||
s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore");
|
||||
}
|
||||
}
|
||||
return rows > 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by 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.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.DcDetailVO;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface DcDetailsDao extends GenericDao<DcDetailVO, Long> {
|
||||
Map<String, String> findDetails(long dcId);
|
||||
|
||||
void persist(long dcId, Map<String, String> details);
|
||||
|
||||
DcDetailVO findDetail(long dcId, String name);
|
||||
|
||||
void deleteDetails(long dcId);
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
||||
// Apache License, Version 2.0 (the "License"); you may not use this
|
||||
// file except in compliance with the License. Citrix Systems, Inc.
|
||||
// reserves all rights not expressly granted by 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.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.DcDetailVO;
|
||||
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Local(value=DcDetailsDao.class)
|
||||
public class DcDetailsDaoImpl extends GenericDaoBase<DcDetailVO, Long> implements DcDetailsDao {
|
||||
protected final SearchBuilder<DcDetailVO> DcSearch;
|
||||
protected final SearchBuilder<DcDetailVO> DetailSearch;
|
||||
|
||||
protected DcDetailsDaoImpl() {
|
||||
DcSearch = createSearchBuilder();
|
||||
DcSearch.and("dcId", DcSearch.entity().getDcId(), SearchCriteria.Op.EQ);
|
||||
DcSearch.done();
|
||||
|
||||
DetailSearch = createSearchBuilder();
|
||||
DetailSearch.and("dcId", DetailSearch.entity().getDcId(), SearchCriteria.Op.EQ);
|
||||
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||
DetailSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DcDetailVO findDetail(long dcId, String name) {
|
||||
SearchCriteria<DcDetailVO> sc = DetailSearch.create();
|
||||
sc.setParameters("dcId", dcId);
|
||||
sc.setParameters("name", name);
|
||||
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> findDetails(long dcId) {
|
||||
SearchCriteria<DcDetailVO> sc = DcSearch.create();
|
||||
sc.setParameters("dcId", dcId);
|
||||
|
||||
List<DcDetailVO> results = search(sc, null);
|
||||
Map<String, String> details = new HashMap<String, String>(results.size());
|
||||
for (DcDetailVO result : results) {
|
||||
details.put(result.getName(), result.getValue());
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDetails(long dcId) {
|
||||
SearchCriteria sc = DcSearch.create();
|
||||
sc.setParameters("dcId", dcId);
|
||||
|
||||
List<DcDetailVO> results = search(sc, null);
|
||||
for (DcDetailVO result : results) {
|
||||
remove(result.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persist(long dcId, Map<String, String> details) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
SearchCriteria<DcDetailVO> sc = DcSearch.create();
|
||||
sc.setParameters("dcId", dcId);
|
||||
expunge(sc);
|
||||
|
||||
for (Map.Entry<String, String> detail : details.entrySet()) {
|
||||
DcDetailVO vo = new DcDetailVO(dcId, detail.getKey(), detail.getValue());
|
||||
persist(vo);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
}
|
||||
|
|
@ -22,21 +22,71 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceManager;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntityImpl;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntityImpl;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.cloud.dc.Pod;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.storage.StoragePool;
|
||||
|
||||
@Component
|
||||
|
||||
|
||||
@Service("provisioningService")
|
||||
@Path("/provisioning")
|
||||
public class ProvisioningServiceImpl implements ProvisioningService {
|
||||
|
||||
|
||||
@Override
|
||||
public StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneEntity registerZone(String zoneUuid, String owner, List<String> tags, Map<String, String> details) {
|
||||
|
||||
ZoneEntityImpl zoneEntity = new ZoneEntityImpl(zoneUuid);
|
||||
zoneEntity.setOwner(owner);
|
||||
zoneEntity.setDetails(details);
|
||||
zoneEntity.setState(State.Disabled);
|
||||
zoneEntity.persist();
|
||||
|
||||
return zoneEntity;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public PodEntity registerPod(String name, List<String> tags, Map<String, String> details) {
|
||||
// // TODO Auto-generated method stub
|
||||
// return null;
|
||||
//}
|
||||
|
||||
@Override
|
||||
public ClusterEntity registerCluster(String name, List<String> tags, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String registerHost(String name, List<String> tags, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregisterStorage(String uuid) {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
@ -90,8 +140,8 @@ public class ProvisioningServiceImpl implements ProvisioningService {
|
|||
@Override
|
||||
public List<ZoneEntity> listZones() {
|
||||
List<ZoneEntity> zones = new ArrayList<ZoneEntity>();
|
||||
zones.add(new ZoneEntityImpl("zone-uuid-1", "name1"));
|
||||
zones.add(new ZoneEntityImpl("zone-uuid-2", "name2"));
|
||||
zones.add(new ZoneEntityImpl("zone-uuid-1"));
|
||||
zones.add(new ZoneEntityImpl("zone-uuid-2"));
|
||||
return zones;
|
||||
}
|
||||
|
||||
|
|
@ -103,38 +153,18 @@ public class ProvisioningServiceImpl implements ProvisioningService {
|
|||
|
||||
@Override
|
||||
public ZoneEntity getZone(String uuid) {
|
||||
ZoneEntityImpl impl = new ZoneEntityImpl(uuid, "name");
|
||||
ZoneEntityImpl impl = new ZoneEntityImpl(uuid);
|
||||
return impl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneEntity registerZone(String name, List<String> tags, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PodEntity registerPod(String name, List<String> tags, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterEntity registerCluster(String name, List<String> tags, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String registerHost(String name, List<String> tags, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public PodEntity registerPod(String arg0, Long arg1, String arg2,
|
||||
String arg3, String arg4, String arg5, List<String> arg6,
|
||||
Map<String, String> arg7) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package org.apache.cloudstack.engine.provisioning.test;
|
||||
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
|
||||
|
||||
|
||||
public class ChildTestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataCenterDao dataCenterDao() {
|
||||
return Mockito.mock(DataCenterDao.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.apache.cloudstack.engine.provisioning.test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao;
|
||||
import org.apache.cloudstack.engine.service.api.ProvisioningService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="classpath:/resource/provisioningContext.xml")
|
||||
public class ProvisioningTest extends TestCase {
|
||||
|
||||
@Inject
|
||||
ProvisioningService service;
|
||||
|
||||
@Inject
|
||||
DataCenterDao dcDao;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24",
|
||||
null, null, NetworkType.Basic, null, null, true, true);
|
||||
|
||||
Mockito.when(dcDao.findById(Mockito.anyLong())).thenReturn(dc);
|
||||
Mockito.when(dcDao.persist((DataCenterVO) Mockito.anyObject())).thenReturn(dc);
|
||||
}
|
||||
|
||||
private void registerAndEnableZone() {
|
||||
ZoneEntity zone = service.registerZone("47547648", "owner", null, new HashMap<String, String>());
|
||||
State state = zone.getState();
|
||||
System.out.println("state:"+state);
|
||||
boolean result = zone.enable();
|
||||
System.out.println("state:"+zone.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProvisioning() {
|
||||
registerAndEnableZone();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:annotation-config />
|
||||
<context:component-scan base-package="org.apache.cloudstack.engine" />
|
||||
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
<!-- bean id="aopTestBean" class="org.apache.cloudstack.storage.test.AopTestAdvice"/-->
|
||||
<!-- aop:config proxy-target-class="true" >
|
||||
<aop:aspect id="AopTestAdvice" ref="aopTestBean">
|
||||
<aop:pointcut id="aoptest"
|
||||
expression="@annotation(com.cloud.utils.db.DB)" />
|
||||
<aop:around pointcut-ref="aoptest" method="AopTestMethod"/>
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
-->
|
||||
|
||||
<bean class="org.apache.cloudstack.engine.provisioning.test.ChildTestConfiguration" />
|
||||
|
||||
</beans>
|
||||
|
|
@ -100,31 +100,26 @@ public class PrimaryDataStoreEntityImpl implements StorageEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails(String source) {
|
||||
public Map<String, String> getDetails() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDetailSources() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String source, String name, String value) {
|
||||
public void addDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String source, String name, String value) {
|
||||
public void delDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String source, String name, String value) {
|
||||
public void updateDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
@ -246,4 +241,10 @@ public class PrimaryDataStoreEntityImpl implements StorageEntity {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persist() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,31 +95,26 @@ public class TemplateEntityImpl implements TemplateEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails(String source) {
|
||||
public Map<String, String> getDetails() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDetailSources() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String source, String name, String value) {
|
||||
public void addDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String source, String name, String value) {
|
||||
public void delDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String source, String name, String value) {
|
||||
public void updateDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
@ -256,12 +251,6 @@ public class TemplateEntityImpl implements TemplateEntity {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getDetails() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
|||
|
|
@ -53,36 +53,6 @@ public class SnapshotEntityImpl implements SnapshotEntity {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails(String source) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDetailSources() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Method> getApplicableActions() {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
@ -179,4 +149,28 @@ public class SnapshotEntityImpl implements SnapshotEntity {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,36 +97,7 @@ public class VolumeEntityImpl implements VolumeEntity {
|
|||
return volumeInfo.getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails(String source) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDetailSources() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Method> getApplicableActions() {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
@ -253,4 +224,28 @@ public class VolumeEntityImpl implements VolumeEntity {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue