You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2012/12/27 22:48:17 UTC
[8/32] Simulator: moving hypervisor simulator into plugin
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d6083ce5/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVolumeDao.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVolumeDao.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVolumeDao.java
new file mode 100644
index 0000000..1fd815c
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVolumeDao.java
@@ -0,0 +1,30 @@
+// 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/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVolumeDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVolumeDaoImpl.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVolumeDaoImpl.java
new file mode 100644
index 0000000..a3a3517
--- /dev/null
+++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVolumeDaoImpl.java
@@ -0,0 +1,101 @@
+// 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/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/pom.xml b/plugins/pom.xml
index d71bd45..65b5971 100644
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -38,6 +38,7 @@
<module>hypervisors/ovm</module>
<module>hypervisors/xen</module>
<module>hypervisors/kvm</module>
+ <module>hypervisors/simulator</module>
<module>network-elements/elastic-loadbalancer</module>
<module>network-elements/ovs</module>
<module>network-elements/nicira-nvp</module>
@@ -124,6 +125,17 @@
<module>hypervisors/vmware</module>
</modules>
</profile>
+ <profile>
+ <id>kvm</id>
+ <activation>
+ <property>
+ <name>nonoss</name>
+ </property>
+ </activation>
+ <modules>
+ <module>hypervisors/simulator</module>
+ </modules>
+ </profile>
</profiles>
</project>