You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2012/12/22 22:03:04 UTC
[4/8] Simulator: moving hypervisor simulator into plugin
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/MockStoragePoolVO.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/MockStoragePoolVO.java b/agent-simulator/src/com/cloud/simulator/MockStoragePoolVO.java
deleted file mode 100644
index 81f0432..0000000
--- a/agent-simulator/src/com/cloud/simulator/MockStoragePoolVO.java
+++ /dev/null
@@ -1,102 +0,0 @@
-// 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.simulator;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import com.cloud.storage.Storage.StoragePoolType;
-
-@Entity
-@Table(name="mockstoragepool")
-
-public class MockStoragePoolVO {
- @Id
- @GeneratedValue(strategy=GenerationType.IDENTITY)
- @Column(name="id")
- private long id;
-
- @Column(name="guid")
- private String uuid;
-
- @Column(name="mount_point")
- private String mountPoint;
-
- @Column(name="capacity")
- private long capacity;
-
- @Column(name="hostguid")
- private String hostGuid;
-
- @Column(name="pool_type")
- @Enumerated(value=EnumType.STRING)
- private StoragePoolType poolType;
-
- public MockStoragePoolVO() {
-
- }
-
- public String getHostGuid() {
- return this.hostGuid;
- }
-
- public void setHostGuid(String hostGuid) {
- this.hostGuid = hostGuid;
- }
-
- public long getId() {
- return this.id;
- }
-
- public StoragePoolType getPoolType() {
- return this.poolType;
- }
-
- public void setStorageType(StoragePoolType poolType) {
- this.poolType = poolType;
- }
-
- public String getUuid() {
- return this.uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- public String getMountPoint() {
- return this.mountPoint;
- }
-
- public void setMountPoint(String mountPoint) {
- this.mountPoint = mountPoint;
- }
-
- public long getCapacity() {
- return this.capacity;
- }
-
- public void setCapacity(long capacity) {
- this.capacity = capacity;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/MockVMVO.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/MockVMVO.java b/agent-simulator/src/com/cloud/simulator/MockVMVO.java
deleted file mode 100644
index c1b391e..0000000
--- a/agent-simulator/src/com/cloud/simulator/MockVMVO.java
+++ /dev/null
@@ -1,130 +0,0 @@
-// 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.simulator;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import com.cloud.vm.VirtualMachine.State;
-
-@Entity
-@Table(name="mockvm")
-
-public class MockVMVO implements MockVm{
- @Id
- @GeneratedValue(strategy=GenerationType.IDENTITY)
- @Column(name="id")
- private long id;
-
- @Column(name="name")
- private String name;
-
- @Column(name="host_id")
- private long hostId;
-
- @Column(name="type")
- private String vmType;
-
- @Column(name="state")
- private State state;
-
- @Column(name="vnc_port")
- private int vncPort;
-
- @Column(name="memory")
- private long memory;
-
- @Column(name="cpu")
- private int cpu;
-
- public MockVMVO() {
-
- }
-
- public long getId() {
- return this.id;
- }
-
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public long getHostId() {
- return this.hostId;
- }
-
- public void setHostId(long hostId) {
- this.hostId = hostId;
- }
-
- public String getVmType() {
- return this.vmType;
- }
-
- public void setVmType(String vmType) {
- this.vmType = vmType;
- }
-
- public State getState() {
- return this.state;
- }
-
- public String getType() {
- return this.vmType;
- }
-
- public void setState(State state) {
- this.state = state;
- }
-
- public int getVncPort() {
- return this.vncPort;
- }
-
- public void setVncPort(int vncPort) {
- this.vncPort = vncPort;
- }
-
- public long getMemory() {
- return this.memory;
- }
-
- public void setMemory(long memory) {
- this.memory = memory;
- }
-
- public int getCpu() {
- return this.cpu;
- }
-
- public void setCpu(int cpu) {
- this.cpu = cpu;
- }
-
- public void setType(String type) {
- this.vmType = type;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/MockVm.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/MockVm.java b/agent-simulator/src/com/cloud/simulator/MockVm.java
deleted file mode 100644
index 250ca7b..0000000
--- a/agent-simulator/src/com/cloud/simulator/MockVm.java
+++ /dev/null
@@ -1,45 +0,0 @@
-// 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.simulator;
-
-import com.cloud.vm.VirtualMachine.State;
-
-// As storage is mapped from storage device, can virtually treat that VM here does
-public interface MockVm {
-
-
- public String getName();
-
- public State getState();
-
- public void setState(State state);
-
- public void setHostId(long hostId);
- public long getMemory();
-
- public int getCpu();
- public String getType();
- public int getVncPort();
-
- public void setName(String name);
- public void setMemory(long memory);
- public void setCpu(int cpu);
- public void setType(String type);
- public void setVncPort(int vncPort);
- public long getId();
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/MockVolumeVO.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/MockVolumeVO.java b/agent-simulator/src/com/cloud/simulator/MockVolumeVO.java
deleted file mode 100644
index 94908d7..0000000
--- a/agent-simulator/src/com/cloud/simulator/MockVolumeVO.java
+++ /dev/null
@@ -1,118 +0,0 @@
-// 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.simulator;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import com.cloud.storage.VMTemplateStorageResourceAssoc;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-
-
-@Entity
-@Table(name="mockvolume")
-
-public class MockVolumeVO {
- public enum MockVolumeType {
- VOLUME,
- TEMPLATE,
- ISO,
- SNAPSHOT;
- }
- @Id
- @GeneratedValue(strategy=GenerationType.IDENTITY)
- @Column(name="id")
- private long id;
-
- @Column(name="name")
- private String name;
-
- @Column(name="size")
- private long size;
-
- @Column(name="path")
- private String path;
-
- @Column(name="pool_id")
- private long poolId;
-
- @Column(name="type")
- @Enumerated(value=EnumType.STRING)
- private MockVolumeType type;
-
- @Column(name="status")
- @Enumerated(value=EnumType.STRING)
- private VMTemplateStorageResourceAssoc.Status status;
-
- public long getId() {
- return id;
- }
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public long getSize() {
- return this.size;
- }
-
- public void setSize(long size) {
- this.size = size;
- }
-
- public String getPath() {
- return this.path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
- public long getPoolId() {
- return this.poolId;
- }
-
- public void setPoolId(long poolId) {
- this.poolId = poolId;
- }
-
- public MockVolumeType getType() {
- return this.type;
- }
-
- public void setType(MockVolumeType type) {
- this.type = type;
- }
-
- public Status getStatus() {
- return this.status;
- }
-
- public void setStatus(Status status) {
- this.status = status;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/SimulatorGuru.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/SimulatorGuru.java b/agent-simulator/src/com/cloud/simulator/SimulatorGuru.java
deleted file mode 100644
index 20457e4..0000000
--- a/agent-simulator/src/com/cloud/simulator/SimulatorGuru.java
+++ /dev/null
@@ -1,59 +0,0 @@
-// 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.simulator;
-
-import javax.ejb.Local;
-
-import com.cloud.agent.api.to.VirtualMachineTO;
-import com.cloud.hypervisor.HypervisorGuru;
-import com.cloud.hypervisor.HypervisorGuruBase;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.storage.GuestOSVO;
-import com.cloud.storage.dao.GuestOSDao;
-import com.cloud.utils.component.Inject;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-@Local(value=HypervisorGuru.class)
-public class SimulatorGuru extends HypervisorGuruBase implements HypervisorGuru {
- @Inject GuestOSDao _guestOsDao;
-
- protected SimulatorGuru() {
- super();
- }
-
- @Override
- public HypervisorType getHypervisorType() {
- return HypervisorType.Simulator;
- }
-
- @Override
- public <T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfile<T> vm) {
- VirtualMachineTO to = toVirtualMachineTO(vm);
-
- // Determine the VM's OS description
- GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
- to.setOs(guestOS.getDisplayName());
-
- return to;
- }
-
- @Override
- public boolean trackVmHostChange() {
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/SimulatorRuntimeException.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/SimulatorRuntimeException.java b/agent-simulator/src/com/cloud/simulator/SimulatorRuntimeException.java
deleted file mode 100644
index ce962a2..0000000
--- a/agent-simulator/src/com/cloud/simulator/SimulatorRuntimeException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-// 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.simulator;
-
-import com.cloud.utils.SerialVersionUID;
-import com.cloud.utils.exception.RuntimeCloudException;
-
-/**
- * wrap exceptions that you know there's no point in dealing with.
- */
-public class SimulatorRuntimeException extends RuntimeCloudException {
-
- private static final long serialVersionUID = SerialVersionUID.CloudRuntimeException;
-
- public SimulatorRuntimeException(String message) {
- super(message);
- }
-
- public SimulatorRuntimeException(String message, Throwable th) {
- super(message, th);
- }
-
- protected SimulatorRuntimeException() {
- super();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockConfigurationDao.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockConfigurationDao.java b/agent-simulator/src/com/cloud/simulator/dao/MockConfigurationDao.java
deleted file mode 100644
index c0b3c6a..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockConfigurationDao.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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.simulator.dao;
-
-import com.cloud.simulator.MockConfigurationVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface MockConfigurationDao extends GenericDao<MockConfigurationVO, Long> {
- MockConfigurationVO findByCommand(Long dcId, Long podId, Long clusterId, Long hostId, String name);
-
- MockConfigurationVO findByNameBottomUP(Long dcId, Long podId,
- Long clusterId, Long hostId, String name);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java b/agent-simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java
deleted file mode 100644
index a65a4a7..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java
+++ /dev/null
@@ -1,142 +0,0 @@
-// 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.simulator.dao;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.Formatter;
-
-import javax.ejb.Local;
-
-import com.cloud.simulator.MockConfigurationVO;
-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={MockConfigurationDao.class})
-public class MockConfigurationDaoImpl extends GenericDaoBase<MockConfigurationVO, Long> implements MockConfigurationDao {
- private SearchBuilder<MockConfigurationVO> _searchByDcIdName;
- private SearchBuilder<MockConfigurationVO> _searchByDcIDPodIdName;
- private SearchBuilder<MockConfigurationVO> _searchByDcIDPodIdClusterIdName;
- private SearchBuilder<MockConfigurationVO> _searchByDcIDPodIdClusterIdHostIdName;
- private SearchBuilder<MockConfigurationVO> _searchByGlobalName;
-
-
- public MockConfigurationDaoImpl() {
- _searchByGlobalName = createSearchBuilder();
- _searchByGlobalName.and("dcId", _searchByGlobalName.entity().getDataCenterId(), SearchCriteria.Op.NULL);
- _searchByGlobalName.and("podId", _searchByGlobalName.entity().getPodId(), SearchCriteria.Op.NULL);
- _searchByGlobalName.and("clusterId", _searchByGlobalName.entity().getClusterId(), SearchCriteria.Op.NULL);
- _searchByGlobalName.and("hostId", _searchByGlobalName.entity().getHostId(), SearchCriteria.Op.NULL);
- _searchByGlobalName.and("name", _searchByGlobalName.entity().getName(), SearchCriteria.Op.EQ);
- _searchByGlobalName.done();
-
- _searchByDcIdName = createSearchBuilder();
- _searchByDcIdName.and("dcId", _searchByDcIdName.entity().getDataCenterId(), SearchCriteria.Op.EQ);
- _searchByDcIdName.and("podId", _searchByDcIdName.entity().getPodId(), SearchCriteria.Op.NULL);
- _searchByDcIdName.and("clusterId", _searchByDcIdName.entity().getClusterId(), SearchCriteria.Op.NULL);
- _searchByDcIdName.and("hostId", _searchByDcIdName.entity().getHostId(), SearchCriteria.Op.NULL);
- _searchByDcIdName.and("name", _searchByDcIdName.entity().getName(), SearchCriteria.Op.EQ);
- _searchByDcIdName.done();
-
- _searchByDcIDPodIdName = createSearchBuilder();
- _searchByDcIDPodIdName.and("dcId", _searchByDcIDPodIdName.entity().getDataCenterId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdName.and("podId", _searchByDcIDPodIdName.entity().getPodId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdName.and("clusterId", _searchByDcIDPodIdName.entity().getClusterId(), SearchCriteria.Op.NULL);
- _searchByDcIDPodIdName.and("hostId", _searchByDcIDPodIdName.entity().getHostId(), SearchCriteria.Op.NULL);
- _searchByDcIDPodIdName.and("name", _searchByDcIDPodIdName.entity().getName(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdName.done();
-
- _searchByDcIDPodIdClusterIdName = createSearchBuilder();
- _searchByDcIDPodIdClusterIdName.and("dcId", _searchByDcIDPodIdClusterIdName.entity().getDataCenterId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdName.and("podId", _searchByDcIDPodIdClusterIdName.entity().getPodId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdName.and("clusterId", _searchByDcIDPodIdClusterIdName.entity().getClusterId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdName.and("hostId", _searchByDcIDPodIdClusterIdName.entity().getHostId(), SearchCriteria.Op.NULL);
- _searchByDcIDPodIdClusterIdName.and("name", _searchByDcIDPodIdClusterIdName.entity().getName(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdName.done();
-
- _searchByDcIDPodIdClusterIdHostIdName = createSearchBuilder();
- _searchByDcIDPodIdClusterIdHostIdName.and("dcId", _searchByDcIDPodIdClusterIdHostIdName.entity().getDataCenterId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdHostIdName.and("podId", _searchByDcIDPodIdClusterIdHostIdName.entity().getPodId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdHostIdName.and("clusterId", _searchByDcIDPodIdClusterIdHostIdName.entity().getClusterId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdHostIdName.and("hostId", _searchByDcIDPodIdClusterIdHostIdName.entity().getHostId(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdHostIdName.and("name", _searchByDcIDPodIdClusterIdHostIdName.entity().getName(), SearchCriteria.Op.EQ);
- _searchByDcIDPodIdClusterIdHostIdName.done();
- }
- @Override
- public MockConfigurationVO findByCommand(Long dcId, Long podId, Long clusterId, Long hostId, String name) {
-
- if (dcId == null) {
- SearchCriteria<MockConfigurationVO> sc = _searchByGlobalName.create();
- sc.setParameters("name", name);
- return findOneBy(sc);
- } else if (podId == null) {
- SearchCriteria<MockConfigurationVO> sc = _searchByDcIdName.create();
- sc.setParameters("name", name);
- sc.setParameters("dcId", dcId);
- return findOneBy(sc);
- } else if (clusterId == null) {
- SearchCriteria<MockConfigurationVO> sc = _searchByDcIDPodIdName.create();
- sc.setParameters("name", name);
- sc.setParameters("dcId", dcId);
- sc.setParameters("podId", podId);
- return findOneBy(sc);
- } else if (hostId == null) {
- SearchCriteria<MockConfigurationVO> sc = _searchByDcIDPodIdClusterIdName.create();
- sc.setParameters("name", name);
- sc.setParameters("dcId", dcId);
- sc.setParameters("podId", podId);
- sc.setParameters("clusterId", clusterId);
- return findOneBy(sc);
- } else {
- SearchCriteria<MockConfigurationVO> sc = _searchByDcIDPodIdClusterIdHostIdName.create();
- sc.setParameters("name", name);
- sc.setParameters("dcId", dcId);
- sc.setParameters("podId", podId);
- sc.setParameters("clusterId", clusterId);
- sc.setParameters("hostId", hostId);
- return findOneBy(sc);
- }
- }
-
- @Override
- public MockConfigurationVO findByNameBottomUP(Long dcId, Long podId, Long clusterId, Long hostId, String name) {
- Transaction txn = Transaction.currentTxn();
- StringBuilder search = new StringBuilder();
- Formatter formatter = new Formatter(search);
- formatter.format("select * from mockconfiguration where (name='%s') and ((data_center_id = %d and pod_id = %d and cluster_id = %d and host_id = %d)", name, dcId, podId, clusterId, hostId);
- formatter.format(" or (data_center_id = %d and pod_id = %d and cluster_id = %d and host_id is null)", dcId, podId, clusterId);
- formatter.format(" or (data_center_id = %d and pod_id = %d and cluster_id is null and host_id is null)", dcId, podId);
- formatter.format(" or (data_center_id = %d and pod_id is null and cluster_id is null and host_id is null)", dcId);
- formatter.format(" or (data_center_id is null and pod_id is null and cluster_id is null and host_id is null)) LIMIT 1");
-
- PreparedStatement pstmt = null;
- try {
- String sql = search.toString();
- pstmt = txn.prepareAutoCloseStatement(sql);
- ResultSet rs = pstmt.executeQuery();
- if (rs.next()) {
- return toEntityBean(rs, false);
- }
- } catch (Exception e) {
-
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockHostDao.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockHostDao.java b/agent-simulator/src/com/cloud/simulator/dao/MockHostDao.java
deleted file mode 100644
index 4732783..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockHostDao.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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.simulator.dao;
-
-import com.cloud.simulator.MockHost;
-import com.cloud.simulator.MockHostVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface MockHostDao extends GenericDao<MockHostVO, Long> {
- public MockHost findByGuid(String guid);
- public MockHost findByVmId(long vmId);
- public boolean removeByGuid(String guid);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockHostDaoImpl.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockHostDaoImpl.java b/agent-simulator/src/com/cloud/simulator/dao/MockHostDaoImpl.java
deleted file mode 100644
index 8c5f8d8..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockHostDaoImpl.java
+++ /dev/null
@@ -1,55 +0,0 @@
-// 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.simulator.dao;
-
-import javax.ejb.Local;
-
-import com.cloud.simulator.MockHost;
-import com.cloud.simulator.MockHostVO;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-
-@Local(value={MockHostDao.class})
-public class MockHostDaoImpl extends GenericDaoBase<MockHostVO, Long> implements MockHostDao {
- protected final SearchBuilder<MockHostVO> GuidSearch;
- public MockHostDaoImpl() {
- GuidSearch = createSearchBuilder();
- GuidSearch.and("guid", GuidSearch.entity().getGuid(), SearchCriteria.Op.EQ);
- GuidSearch.done();
- }
- @Override
- public MockHost findByGuid(String guid) {
- SearchCriteria<MockHostVO> sc = GuidSearch.create();
- sc.setParameters("guid", guid);
- return findOneBy(sc);
- }
- @Override
- public MockHost findByVmId(long vmId) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean removeByGuid(String guid) {
- MockHost host = this.findByGuid(guid);
- if (host == null) {
- return false;
- }
- return this.remove(host.getId());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockSecStorageDao.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockSecStorageDao.java b/agent-simulator/src/com/cloud/simulator/dao/MockSecStorageDao.java
deleted file mode 100644
index fc19f63..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockSecStorageDao.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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.simulator.dao;
-
-import com.cloud.simulator.MockSecStorageVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface MockSecStorageDao extends GenericDao<MockSecStorageVO, Long> {
- public MockSecStorageVO findByUrl(String url);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockSecStorageDaoImpl.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockSecStorageDaoImpl.java b/agent-simulator/src/com/cloud/simulator/dao/MockSecStorageDaoImpl.java
deleted file mode 100644
index fd8d1d3..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockSecStorageDaoImpl.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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.simulator.dao;
-
-import javax.ejb.Local;
-
-import com.cloud.simulator.MockSecStorageVO;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-
-@Local(value={MockSecStorageDao.class})
-public class MockSecStorageDaoImpl extends GenericDaoBase<MockSecStorageVO, Long> implements MockSecStorageDao {
- protected final SearchBuilder<MockSecStorageVO> urlSearch;
- @Override
- public MockSecStorageVO findByUrl(String url) {
- SearchCriteria<MockSecStorageVO> sc = urlSearch.create();
- sc.setParameters("url", url);
- return findOneBy(sc);
- }
-
- public MockSecStorageDaoImpl() {
- urlSearch = createSearchBuilder();
- urlSearch.and("url", urlSearch.entity().getUrl(), SearchCriteria.Op.EQ);
- urlSearch.done();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockSecurityRulesDao.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockSecurityRulesDao.java b/agent-simulator/src/com/cloud/simulator/dao/MockSecurityRulesDao.java
deleted file mode 100644
index ecc69f1..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockSecurityRulesDao.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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.simulator.dao;
-
-import java.util.List;
-
-import com.cloud.simulator.MockSecurityRulesVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface MockSecurityRulesDao extends GenericDao<MockSecurityRulesVO, Long> {
- public MockSecurityRulesVO findByVmId(Long vmId);
- public List<MockSecurityRulesVO> findByHost(String hostGuid);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockSecurityRulesDaoImpl.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockSecurityRulesDaoImpl.java b/agent-simulator/src/com/cloud/simulator/dao/MockSecurityRulesDaoImpl.java
deleted file mode 100644
index 43a1da6..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockSecurityRulesDaoImpl.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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.simulator.dao;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import com.cloud.simulator.MockSecurityRulesVO;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-@Local(value={MockSecurityRulesDao.class})
-public class MockSecurityRulesDaoImpl extends GenericDaoBase<MockSecurityRulesVO, Long> implements MockSecurityRulesDao {
- protected SearchBuilder<MockSecurityRulesVO> vmIdSearch;
- protected SearchBuilder<MockSecurityRulesVO> hostSearch;
- @Override
- public MockSecurityRulesVO findByVmId(Long vmId) {
- SearchCriteria<MockSecurityRulesVO> sc = vmIdSearch.create();
- sc.setParameters("vmId", vmId);
- return findOneBy(sc);
- }
-
- @Override
- public List<MockSecurityRulesVO> findByHost(String hostGuid) {
- SearchCriteria<MockSecurityRulesVO> sc = hostSearch.create();
- sc.setParameters("host", hostGuid);
- return listBy(sc);
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
- vmIdSearch = createSearchBuilder();
- vmIdSearch.and("vmId", vmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ);
- vmIdSearch.done();
-
- hostSearch = createSearchBuilder();
- hostSearch.and("host", hostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
- hostSearch.done();
-
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockStoragePoolDao.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockStoragePoolDao.java b/agent-simulator/src/com/cloud/simulator/dao/MockStoragePoolDao.java
deleted file mode 100644
index e1b4f42..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockStoragePoolDao.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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.simulator.dao;
-
-import com.cloud.simulator.MockStoragePoolVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface MockStoragePoolDao extends GenericDao<MockStoragePoolVO, Long> {
- public MockStoragePoolVO findByUuid(String uuid);
- public MockStoragePoolVO findByHost(String hostUuid);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockStoragePoolDaoImpl.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockStoragePoolDaoImpl.java b/agent-simulator/src/com/cloud/simulator/dao/MockStoragePoolDaoImpl.java
deleted file mode 100644
index e35b537..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockStoragePoolDaoImpl.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// 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.simulator.dao;
-
-import javax.ejb.Local;
-
-import com.cloud.simulator.MockStoragePoolVO;
-import com.cloud.storage.Storage.StoragePoolType;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-
-@Local(value={MockStoragePoolDao.class})
-public class MockStoragePoolDaoImpl extends GenericDaoBase<MockStoragePoolVO, Long> implements MockStoragePoolDao {
- protected final SearchBuilder<MockStoragePoolVO> uuidSearch;
- protected final SearchBuilder<MockStoragePoolVO> hostguidSearch;
- @Override
- public MockStoragePoolVO findByUuid(String uuid) {
- SearchCriteria<MockStoragePoolVO> sc = uuidSearch.create();
- sc.setParameters("uuid", uuid);
- return findOneBy(sc);
- }
-
- public MockStoragePoolDaoImpl() {
- uuidSearch = createSearchBuilder();
- uuidSearch.and("uuid", uuidSearch.entity().getUuid(), SearchCriteria.Op.EQ);
- uuidSearch.done();
-
- hostguidSearch = createSearchBuilder();
- hostguidSearch.and("hostguid", hostguidSearch.entity().getHostGuid(), SearchCriteria.Op.EQ);
- hostguidSearch.and("type", hostguidSearch.entity().getPoolType(), SearchCriteria.Op.EQ);
- hostguidSearch.done();
- }
-
- @Override
- public MockStoragePoolVO findByHost(String hostUuid) {
- SearchCriteria<MockStoragePoolVO> sc = hostguidSearch.create();
- sc.setParameters("hostguid", hostUuid);
- sc.setParameters("type", StoragePoolType.Filesystem.toString());
- return findOneBy(sc);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockVMDao.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockVMDao.java b/agent-simulator/src/com/cloud/simulator/dao/MockVMDao.java
deleted file mode 100644
index fd4d708..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockVMDao.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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.simulator.dao;
-
-import java.util.List;
-
-import com.cloud.simulator.MockVMVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface MockVMDao extends GenericDao<MockVMVO, Long> {
- public List<MockVMVO> findByHostId(long hostId);
- public List<MockVMVO> findByHostGuid(String guid);
- public MockVMVO findByVmName(String vmName);
- public MockVMVO findByVmNameAndHost(String vmName, String hostGuid);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java b/agent-simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
deleted file mode 100644
index 6bd2213..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
+++ /dev/null
@@ -1,92 +0,0 @@
-// 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.simulator.dao;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import com.cloud.simulator.MockHostVO;
-import com.cloud.simulator.MockVMVO;
-import com.cloud.utils.component.Inject;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.JoinBuilder;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.vm.VirtualMachine;
-
-@Local(value={MockVMDao.class})
-public class MockVMDaoImpl extends GenericDaoBase<MockVMVO, Long> implements MockVMDao {
- protected SearchBuilder<MockVMVO> GuidSearch;
- protected SearchBuilder<MockVMVO> vmNameSearch;
- protected SearchBuilder<MockVMVO> vmhostSearch;
- @Inject MockHostDao _mockHostDao;
- @Override
- public List<MockVMVO> findByHostId(long hostId) {
- return new ArrayList<MockVMVO>();
- }
-
- @Override
- public MockVMVO findByVmName(String vmName) {
- SearchCriteria<MockVMVO> sc = vmNameSearch.create();
- sc.setParameters("name", vmName);
- return findOneBy(sc);
- }
-
- @Override
- public List<MockVMVO> findByHostGuid(String guid) {
- SearchCriteria<MockVMVO> sc = GuidSearch.create();
- sc.setJoinParameters("host", "guid", guid);
- sc.setParameters("state", VirtualMachine.State.Running);
- return listBy(sc);
- }
-
- @Override
- public MockVMVO findByVmNameAndHost(String vmName, String hostGuid) {
- SearchCriteria<MockVMVO> sc = vmhostSearch.create();
- sc.setJoinParameters("host", "guid", hostGuid);
- sc.setParameters("name", vmName);
- return findOneBy(sc);
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
- SearchBuilder<MockHostVO> host = _mockHostDao.createSearchBuilder();
- host.and("guid", host.entity().getGuid(), SearchCriteria.Op.EQ);
-
- GuidSearch = createSearchBuilder();
- GuidSearch.join("host", host, host.entity().getId(), GuidSearch.entity().getHostId(), JoinBuilder.JoinType.INNER);
- GuidSearch.and("state", GuidSearch.entity().getState(), SearchCriteria.Op.EQ);
- GuidSearch.done();
-
- vmNameSearch = createSearchBuilder();
- vmNameSearch.and("name", vmNameSearch.entity().getName(), SearchCriteria.Op.EQ);
- vmNameSearch.done();
-
- SearchBuilder<MockHostVO> newhost = _mockHostDao.createSearchBuilder();
- newhost.and("guid", newhost.entity().getGuid(), SearchCriteria.Op.EQ);
- vmhostSearch = createSearchBuilder();
- vmhostSearch.and("name", vmhostSearch.entity().getName(), SearchCriteria.Op.EQ);
- vmhostSearch.join("host", newhost, newhost.entity().getId(), vmhostSearch.entity().getHostId(), JoinBuilder.JoinType.INNER);
- vmhostSearch.done();
-
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockVolumeDao.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockVolumeDao.java b/agent-simulator/src/com/cloud/simulator/dao/MockVolumeDao.java
deleted file mode 100644
index 1fd815c..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockVolumeDao.java
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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.simulator.dao;
-
-import java.util.List;
-
-import com.cloud.simulator.MockVolumeVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface MockVolumeDao extends GenericDao<MockVolumeVO, Long> {
- public List<MockVolumeVO> findByStorageIdAndType(long id, MockVolumeVO.MockVolumeType type);
- public MockVolumeVO findByStoragePathAndType(String path);
- public MockVolumeVO findByNameAndPool(String volumeName, String poolUUID);
- public MockVolumeVO findByName(String volumeName);
- Long findTotalStorageId(long id);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/agent-simulator/src/com/cloud/simulator/dao/MockVolumeDaoImpl.java
----------------------------------------------------------------------
diff --git a/agent-simulator/src/com/cloud/simulator/dao/MockVolumeDaoImpl.java b/agent-simulator/src/com/cloud/simulator/dao/MockVolumeDaoImpl.java
deleted file mode 100644
index 87b54f1..0000000
--- a/agent-simulator/src/com/cloud/simulator/dao/MockVolumeDaoImpl.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// 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.simulator.dao;
-
-import java.util.List;
-
-import javax.ejb.Local;
-
-import com.cloud.simulator.MockVolumeVO;
-import com.cloud.simulator.MockVolumeVO.MockVolumeType;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.GenericSearchBuilder;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.SearchCriteria.Func;
-
-@Local(value={MockVolumeDao.class})
-public class MockVolumeDaoImpl extends GenericDaoBase<MockVolumeVO, Long> implements MockVolumeDao {
- protected final SearchBuilder<MockVolumeVO> idTypeSearch;
- protected final SearchBuilder<MockVolumeVO> pathTypeSearch;
- protected final SearchBuilder<MockVolumeVO> namePoolSearch;
- protected final SearchBuilder<MockVolumeVO> nameSearch;
- protected final GenericSearchBuilder<MockVolumeVO, Long> totalSearch;
- @Override
- public List<MockVolumeVO> findByStorageIdAndType(long id, MockVolumeType type) {
- SearchCriteria<MockVolumeVO> sc = idTypeSearch.create();
- sc.setParameters("storageId", id);
- sc.setParameters("type", type);
- return listBy(sc);
- }
-
- @Override
- public Long findTotalStorageId(long id) {
- SearchCriteria<Long> sc = totalSearch.create();
-
- sc.setParameters("poolId", id);
- return customSearch(sc, null).get(0);
- }
-
- @Override
- public MockVolumeVO findByStoragePathAndType(String path) {
- SearchCriteria<MockVolumeVO> sc = pathTypeSearch.create();
- sc.setParameters("path", "%" + path + "%");
- return findOneBy(sc);
- }
-
- @Override
- public MockVolumeVO findByNameAndPool(String volumeName, String poolUUID) {
- SearchCriteria<MockVolumeVO> sc = namePoolSearch.create();
- sc.setParameters("name", volumeName);
- sc.setParameters("poolUuid", poolUUID);
- return findOneBy(sc);
- }
-
- @Override
- public MockVolumeVO findByName(String volumeName) {
- SearchCriteria<MockVolumeVO> sc = nameSearch.create();
- sc.setParameters("name", volumeName);
- return findOneBy(sc);
- }
-
- public MockVolumeDaoImpl() {
- idTypeSearch = createSearchBuilder();
- idTypeSearch.and("storageId", idTypeSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
- idTypeSearch.and("type", idTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
- idTypeSearch.done();
-
- pathTypeSearch = createSearchBuilder();
- pathTypeSearch.and("path", pathTypeSearch.entity().getPath(), SearchCriteria.Op.LIKE);
- pathTypeSearch.done();
-
- namePoolSearch = createSearchBuilder();
- namePoolSearch.and("name", namePoolSearch.entity().getName(), SearchCriteria.Op.EQ);
- namePoolSearch.and("poolUuid", namePoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
- namePoolSearch.done();
-
- nameSearch = createSearchBuilder();
- nameSearch.and("name", nameSearch.entity().getName(), SearchCriteria.Op.EQ);
- nameSearch.done();
-
- totalSearch = createSearchBuilder(Long.class);
- totalSearch.select(null, Func.SUM, totalSearch.entity().getSize());
- totalSearch.and("poolId", totalSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
- totalSearch.done();
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/pom.xml b/plugins/hypervisors/simulator/pom.xml
new file mode 100644
index 0000000..15b3790
--- /dev/null
+++ b/plugins/hypervisors/simulator/pom.xml
@@ -0,0 +1,45 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloudstack-plugins</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-plugin-hypervisor-simulator</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
+ <name>Apache CloudStack Plugin - Hypervisor Simulator</name>
+ <description>Simulator Hypervisor for Cloudstack</description>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <sourceDirectory>src</sourceDirectory>
+ <testSourceDirectory>test</testSourceDirectory>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/src/com/cloud/agent/MetricsCollector.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/MetricsCollector.java b/plugins/hypervisors/simulator/src/com/cloud/agent/MetricsCollector.java
new file mode 100644
index 0000000..fd611f8
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/MetricsCollector.java
@@ -0,0 +1,107 @@
+// 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.agent;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.utils.concurrency.NamedThreadFactory;
+
+public class MetricsCollector {
+ private static final Logger s_logger = Logger.getLogger(MetricsCollector.class);
+
+ private final Set<String> vmNames = new HashSet<String>();
+ private final Set<String> newVMnames = new HashSet<String>();
+ private final Map<String, MockVmMetrics> metricsMap = new HashMap<String, MockVmMetrics>();
+
+ private final transient ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("Metrics"));
+
+ private Set<String> _currentVms;
+
+ public MetricsCollector(Set<String> currentVms) {
+ _currentVms = currentVms;
+ getAllVMNames();
+ }
+
+ public MetricsCollector() {
+
+ }
+
+ public synchronized void getAllVMNames() {
+ Set<String> currentVMs = _currentVms;
+
+ newVMnames.clear();
+ newVMnames.addAll(currentVMs);
+ newVMnames.removeAll(vmNames); //leave only new vms
+
+ vmNames.removeAll(currentVMs); //old vms - current vms --> leave non-running vms;
+ for (String vm: vmNames) {
+ removeVM(vm);
+ }
+
+ vmNames.clear();
+ vmNames.addAll(currentVMs);
+ }
+
+ public synchronized void submitMetricsJobs() {
+ s_logger.debug("Submit Metric Jobs called");
+
+ for (String vm : newVMnames) {
+ MockVmMetrics task = new MockVmMetrics(vm);
+ if (!metricsMap.containsKey(vm)) {
+ metricsMap.put(vm, task);
+ ScheduledFuture<?> sf = executor.scheduleWithFixedDelay(task, 2, 600, TimeUnit.SECONDS);
+ task.setFuture(sf);
+ }
+ }
+ newVMnames.clear();
+ }
+
+ public synchronized void addVM(String vmName) {
+ newVMnames.add(vmName);
+ s_logger.debug("Added vm name= " + vmName);
+ }
+
+ public synchronized void removeVM(String vmName) {
+ newVMnames.remove(vmName);
+ vmNames.remove(vmName);
+ MockVmMetrics task = metricsMap.get(vmName);
+ if (task != null) {
+ task.stop();
+ boolean r1= task.getFuture().cancel(false);
+ metricsMap.remove(vmName);
+ s_logger.debug("removeVM: cancel returned " + r1 + " for VM " + vmName);
+ } else {
+ s_logger.warn("removeVM called for nonexistent VM " + vmName);
+ }
+ }
+
+ public synchronized Set<String> getVMNames() {
+ return vmNames;
+ }
+
+ public synchronized Map<String, MockVmMetrics> getMetricsMap() {
+ return metricsMap;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/src/com/cloud/agent/MockVmMetrics.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/MockVmMetrics.java b/plugins/hypervisors/simulator/src/com/cloud/agent/MockVmMetrics.java
new file mode 100644
index 0000000..30b99e7
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/MockVmMetrics.java
@@ -0,0 +1,204 @@
+// 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.agent;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.ScheduledFuture;
+
+import org.apache.log4j.Logger;
+
+public class MockVmMetrics implements Runnable {
+ private static final Logger s_logger = Logger.getLogger(MockVmMetrics.class);
+
+ private String vmName;
+
+ public final int MAX_INTERFACES=1;
+
+ public final int MAX_DISKS=8;
+
+ //the last calculated traffic speed (transmit) per interface
+ private Map<String, Double> netTxKBps = new HashMap<String, Double>();
+
+ //the last calculated traffic speed (receive) per interface
+ private Map<String, Double> netRxKBps = new HashMap<String, Double>();
+
+ //the last calculated disk write speed per disk (Bytes Per Second)
+ private Map<String, Double> diskWriteKBytesPerSec = new HashMap<String, Double>();
+
+ //the last calculated disk read speed per disk (Bytes Per Second)
+ private Map<String, Double> diskReadKBytesPerSec = new HashMap<String, Double>();
+
+ //Total Bytes Transmitted on network interfaces
+ private Map<String, Long> netTxTotalBytes = new HashMap<String, Long>();
+
+ //Total Bytes Received on network interfaces
+ private Map<String, Long> netRxTotalBytes = new HashMap<String, Long>();
+
+ //Total Bytes read per disk
+ private Map<String, Long> diskReadTotalBytes = new HashMap<String, Long>();
+
+ //Total Bytes written per disk
+ private Map<String, Long> diskWriteTotalBytes = new HashMap<String, Long>();
+
+ //CPU time in seconds
+ private Double cpuSeconds = new Double(0.0);
+
+ //CPU percentage
+ private Float cpuPercent = new Float(0.0);
+
+ private Map<String, String> diskMap = new HashMap<String, String>();
+
+ private Map<String, String> vifMap = new HashMap<String, String>();
+
+ private Map<String, Long> diskStatTimestamp = new HashMap<String, Long>();
+ private Map<String, Long> netStatTimestamp = new HashMap<String, Long>();
+
+ private long cpuStatTimestamp = 0L;
+
+ private ScheduledFuture<?> future;
+ private boolean stopped = false;
+ private Random randSeed = new Random();
+
+ public MockVmMetrics(String vmName) {
+ this.vmName = vmName;
+ vifMap.put("eth0", "eth0");
+ vifMap.put("eth1", "eth1");
+ vifMap.put("eth2", "eth2");
+
+ Long networkStart = 0L;
+ netTxTotalBytes.put("eth0", networkStart);
+ netRxTotalBytes.put("eth0", networkStart);
+
+ netTxTotalBytes.put("eth1", networkStart);
+ netRxTotalBytes.put("eth1", networkStart);
+
+ netTxTotalBytes.put("eth2", networkStart);
+ netRxTotalBytes.put("eth2", networkStart);
+ }
+
+ private int getIncrementor() {
+ return randSeed.nextInt(100);
+ }
+
+ @Override
+ public void run() {
+ if(s_logger.isDebugEnabled()) {
+ s_logger.debug("Generating MockVM metrics");
+ }
+ for (Map.Entry<String, Long> entry : netRxTotalBytes.entrySet()) {
+ entry.setValue(entry.getValue() + getIncrementor());
+ }
+
+ for (Map.Entry<String, Long> entry : netTxTotalBytes.entrySet()) {
+ entry.setValue(entry.getValue() + getIncrementor());
+ }
+ }
+
+ public String getVmName() {
+ return vmName;
+ }
+
+ public Map<String, Double> getNetTxKBps() {
+ return netTxKBps;
+ }
+
+ public Map<String, Double> getNetRxKBps() {
+ return netRxKBps;
+ }
+
+ public Map<String, Double> getDiskWriteBytesPerSec() {
+ return diskWriteKBytesPerSec;
+ }
+
+ public Map<String, Double> getDiskReadBytesPerSec() {
+ return diskReadKBytesPerSec;
+ }
+
+ public Map<String, Long> getNetTxTotalBytes() {
+ return netTxTotalBytes;
+ }
+
+ public Map<String, Long> getNetRxTotalBytes() {
+ return netRxTotalBytes;
+ }
+
+ public Map<String, Long> getDiskReadTotalBytes() {
+ return diskReadTotalBytes;
+ }
+
+ public Map<String, Long> getDiskWriteTotalBytes() {
+ return diskWriteTotalBytes;
+ }
+
+ public Double getNetTxKBps(String intf) {
+ return netTxKBps.get(intf);
+ }
+
+ public Double getNetRxKBps(String intf) {
+ return netRxKBps.get(intf);
+ }
+
+ public Double getDiskWriteKBytesPerSec(String disk) {
+ return diskWriteKBytesPerSec.get(disk);
+ }
+
+ public Double getDiskReadKBytesPerSec(String disk) {
+ return diskReadKBytesPerSec.get(disk);
+ }
+
+ public Long getNetTxTotalBytes(String intf) {
+ return netTxTotalBytes.get(intf);
+ }
+
+ public Long getNetRxTotalBytes(String intf) {
+ return netRxTotalBytes.get(intf);
+ }
+
+ public Long getDiskReadTotalBytes(String disk) {
+ return diskReadTotalBytes.get(disk);
+ }
+
+ public Long getDiskWriteTotalBytes(String disk) {
+ return diskWriteTotalBytes.get(disk);
+ }
+
+ public Double getCpuSeconds() {
+ return cpuSeconds;
+ }
+
+ public Map<String, String> getDiskMap() {
+ return diskMap;
+ }
+
+ public Float getCpuPercent() {
+ return cpuPercent;
+ }
+
+ public void setFuture(ScheduledFuture<?> sf) {
+ this.future = sf;
+ }
+
+ public ScheduledFuture<?> getFuture() {
+ return future;
+ }
+
+ public void stop() {
+ this.stopped = true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/src/com/cloud/agent/MultiCaster.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/MultiCaster.java b/plugins/hypervisors/simulator/src/com/cloud/agent/MultiCaster.java
new file mode 100644
index 0000000..7d38baf
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/MultiCaster.java
@@ -0,0 +1,152 @@
+// 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.agent;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+public class MultiCaster implements Runnable {
+ private static final Logger s_logger = Logger.getLogger(MultiCaster.class);
+
+ public final int MAX_PACKET_SIZE = 8096;
+
+ private List<MultiCasterListener> listeners;
+ private DatagramSocket socket;
+ private byte[] recvBuffer;
+
+ private Thread driver;
+ private volatile boolean stopRequested = false;
+
+ public MultiCaster() {
+ listeners = new ArrayList<MultiCasterListener>();
+ recvBuffer = new byte[MAX_PACKET_SIZE];
+ }
+
+ public void addListener(MultiCasterListener listener) {
+ synchronized(listeners) {
+ listeners.add(listener);
+ }
+ }
+
+ public void removeListener(MultiCasterListener listener) {
+ synchronized(listeners) {
+ listeners.remove(listener);
+ }
+ }
+
+ public void cast(byte[] buf, int off, int len,
+ InetAddress toAddress, int nToPort) throws IOException {
+
+ if(socket == null)
+ throw new IOException("multi caster is not started");
+
+ if(len >= MAX_PACKET_SIZE)
+ throw new IOException("packet size exceeds limit of " + MAX_PACKET_SIZE);
+
+ DatagramPacket packet = new DatagramPacket(buf, off,
+ len, toAddress, nToPort);
+
+ socket.send(packet);
+ }
+
+ public void start(String strOutboundAddress,
+ String strClusterAddress, int nPort) throws SocketException {
+ assert(socket == null);
+
+ InetAddress addr = null;
+ try {
+ addr = InetAddress.getByName(strClusterAddress);
+ } catch(IOException e) {
+ s_logger.error("Unexpected exception " , e);
+ }
+
+ if(addr != null && addr.isMulticastAddress()) {
+ try {
+ socket = new MulticastSocket(nPort);
+ socket.setReuseAddress(true);
+
+ if(s_logger.isInfoEnabled())
+ s_logger.info("Join multicast group : " + addr);
+
+ ((MulticastSocket)socket).joinGroup(addr);
+ ((MulticastSocket)socket).setTimeToLive(1);
+
+ if(strOutboundAddress != null) {
+ if(s_logger.isInfoEnabled())
+ s_logger.info("set outgoing interface to : " + strOutboundAddress);
+
+ InetAddress ia = InetAddress.getByName(strOutboundAddress);
+ NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
+ ((MulticastSocket)socket).setNetworkInterface(ni);
+ }
+ } catch(IOException e) {
+ s_logger.error("Unexpected exception " , e);
+ }
+ } else {
+ socket = new DatagramSocket(nPort);
+ socket.setReuseAddress(true);
+ }
+
+ driver = new Thread(this, "Multi-caster");
+ driver.setDaemon(true);
+ driver.start();
+ }
+
+ public void stop() {
+ if(socket != null) {
+ stopRequested = true;
+
+ socket.close();
+ if(driver != null) {
+ try {
+ driver.join();
+ } catch(InterruptedException e) {
+ }
+ driver = null;
+ }
+ }
+
+ socket = null;
+ stopRequested = false;
+ }
+
+ public void run() {
+ while(!stopRequested) {
+ try {
+ DatagramPacket packet = new DatagramPacket(recvBuffer, recvBuffer.length);
+ socket.receive(packet);
+
+ for(Object listener : listeners.toArray()) {
+ ((MultiCasterListener)listener).onMultiCasting(packet.getData(),
+ packet.getOffset(), packet.getLength(), packet.getAddress());
+ }
+ } catch(IOException e) {
+ } catch(Throwable e) {
+ s_logger.error("Unhandled exception : ", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/src/com/cloud/agent/MultiCasterListener.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/MultiCasterListener.java b/plugins/hypervisors/simulator/src/com/cloud/agent/MultiCasterListener.java
new file mode 100644
index 0000000..fe4761b
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/MultiCasterListener.java
@@ -0,0 +1,22 @@
+// 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.agent;
+import java.net.InetAddress;
+
+public interface MultiCasterListener {
+ public void onMultiCasting(byte[] data, int off, int len, InetAddress addrFrom);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/src/com/cloud/agent/SimulatorCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/SimulatorCmd.java b/plugins/hypervisors/simulator/src/com/cloud/agent/SimulatorCmd.java
new file mode 100644
index 0000000..caed518
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/SimulatorCmd.java
@@ -0,0 +1,37 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.agent;
+
+import java.io.Serializable;
+
+public class SimulatorCmd implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String testCase = "DEFAULT";
+
+ public SimulatorCmd(String testCase) {
+ this.testCase = testCase;
+ }
+
+ public String getTestCase() {
+ return testCase;
+ }
+
+ public void setTestCase(String testCase) {
+ this.testCase = testCase;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/src/com/cloud/agent/SimulatorMigrateVmCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/SimulatorMigrateVmCmd.java b/plugins/hypervisors/simulator/src/com/cloud/agent/SimulatorMigrateVmCmd.java
new file mode 100644
index 0000000..6a2190d
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/SimulatorMigrateVmCmd.java
@@ -0,0 +1,83 @@
+// 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.agent;
+
+public class SimulatorMigrateVmCmd extends SimulatorCmd {
+
+ private static final long serialVersionUID = 1L;
+
+ private String destIp;
+
+ private String vmName;
+ private long ramSize;
+ private int cpuCount;
+ private int utilization;
+
+ public SimulatorMigrateVmCmd(String testCase) {
+ super(testCase);
+ }
+
+ public String getDestIp() {
+ return destIp;
+ }
+
+ public void setDestIp(String destIp) {
+ this.destIp = destIp;
+ }
+
+ public String getVmName() {
+ return vmName;
+ }
+
+ public void setVmName(String vmName) {
+ this.vmName = vmName;
+ }
+
+ public long getRamSize() {
+ return ramSize;
+ }
+
+ public void setRamSize(long ramSize) {
+ this.ramSize = ramSize;
+ }
+
+ public int getCpuCount() {
+ return cpuCount;
+ }
+
+ public void setCpuCount(int cpuCount) {
+ this.cpuCount = cpuCount;
+ }
+
+ public int getUtilization() {
+ return utilization;
+ }
+
+ public void setUtilization(int utilization) {
+ this.utilization = utilization;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("SimulatorMigrateVmCmd {").append("vm: ").append(getVmName());
+ sb.append(", destIp: ").append(getDestIp()).append(", ramSize: ").append(getRamSize());
+ sb.append(", cpuCount: ").append(getCpuCount()).append(", utilization: ").append(getUtilization());
+ sb.append("}");
+
+ return sb.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java
new file mode 100644
index 0000000..7db5b20
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java
@@ -0,0 +1,66 @@
+// 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.agent.manager;
+
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.CheckHealthCommand;
+import com.cloud.agent.api.CheckNetworkCommand;
+import com.cloud.agent.api.GetHostStatsAnswer;
+import com.cloud.agent.api.GetHostStatsCommand;
+import com.cloud.agent.api.MaintainCommand;
+import com.cloud.agent.api.PingTestCommand;
+import com.cloud.agent.api.PrepareForMigrationCommand;
+import com.cloud.resource.AgentResourceBase;
+import com.cloud.simulator.MockHost;
+import com.cloud.utils.component.Manager;
+
+public interface MockAgentManager extends Manager {
+ public static final long DEFAULT_HOST_MEM_SIZE = 8 * 1024 * 1024 * 1024L; // 8G,
+ // unit
+ // of
+ // Mbytes
+ public static final int DEFAULT_HOST_CPU_CORES = 4; // 2 dual core CPUs (2 x
+ // 2)
+ public static final int DEFAULT_HOST_SPEED_MHZ = 8000; // 1 GHz CPUs
+
+ boolean configure(String name, Map<String, Object> params) throws ConfigurationException;
+
+ Map<AgentResourceBase, Map<String, String>> createServerResources(Map<String, Object> params);
+
+ boolean handleSystemVMStart(long vmId, String privateIpAddress, String privateMacAddress, String privateNetMask,
+ long dcId, long podId, String name, String vmType, String url);
+
+ boolean handleSystemVMStop(long vmId);
+
+ GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd);
+
+ Answer checkHealth(CheckHealthCommand cmd);
+
+ Answer pingTest(PingTestCommand cmd);
+
+ Answer prepareForMigrate(PrepareForMigrationCommand cmd);
+
+ MockHost getHost(String guid);
+
+ Answer maintain(MaintainCommand cmd);
+
+ Answer checkNetworkCommand(CheckNetworkCommand cmd);
+}