http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7e61e200/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java new file mode 100644 index 0000000..2ad3631 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostTagsDaoImpl.java @@ -0,0 +1,75 @@ +// 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 org.apache.cloudstack.engine.datacenter.entity.api.db.dao; + +import java.util.ArrayList; +import java.util.List; + +import javax.ejb.Local; + +import org.springframework.stereotype.Component; + +import com.cloud.host.HostTagVO; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; + +@Component +@Local(value=HostTagsDao.class) +public class HostTagsDaoImpl extends GenericDaoBase<HostTagVO, Long> implements HostTagsDao { + protected final SearchBuilder<HostTagVO> HostSearch; + + protected HostTagsDaoImpl() { + HostSearch = createSearchBuilder(); + HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); + HostSearch.done(); + } + + @Override + public List<String> gethostTags(long hostId) { + SearchCriteria<HostTagVO> sc = HostSearch.create(); + sc.setParameters("hostId", hostId); + + List<HostTagVO> results = search(sc, null); + List<String> hostTags = new ArrayList<String>(results.size()); + for (HostTagVO result : results) { + hostTags.add(result.getTag()); + } + + return hostTags; + } + + @Override + public void persist(long hostId, List<String> hostTags) { + Transaction txn = Transaction.currentTxn(); + + txn.start(); + SearchCriteria<HostTagVO> sc = HostSearch.create(); + sc.setParameters("hostId", hostId); + expunge(sc); + + for (String tag : hostTags) { + tag = tag.trim(); + if(tag.length() > 0) { + HostTagVO vo = new HostTagVO(hostId, tag); + persist(vo); + } + } + txn.commit(); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7e61e200/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java index 2dc652f..f503530 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java @@ -32,6 +32,8 @@ import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity; import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntityImpl; 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.HostEntity; +import org.apache.cloudstack.engine.datacenter.entity.api.HostEntityImpl; 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; @@ -89,9 +91,14 @@ public class ProvisioningServiceImpl implements ProvisioningService { } @Override - public String registerHost(String name, List<String> tags, Map<String, String> details) { - // TODO Auto-generated method stub - return null; + public HostEntity registerHost(String hostUuid, String name, String owner, List<String> tags, Map<String, String> details) { + HostEntityImpl hostEntity = new HostEntityImpl(hostUuid, manager); + hostEntity.setOwner(owner); + hostEntity.setName(name); + hostEntity.setDetails(details); + + hostEntity.persist(); + return hostEntity; } @Override @@ -120,9 +127,9 @@ public class ProvisioningServiceImpl implements ProvisioningService { } @Override - public void deregisterHost() { - // TODO Auto-generated method stub - + public void deregisterHost(String uuid) { + HostEntityImpl hostEntity = new HostEntityImpl(uuid, manager); + hostEntity.disable(); } @Override http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7e61e200/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java index 13e44ab..72f956e 100644 --- a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java +++ b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java @@ -3,6 +3,7 @@ package org.apache.cloudstack.engine.provisioning.test; import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.ClusterDao; import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao; +import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.HostDao; import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.HostPodDao; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; @@ -27,4 +28,8 @@ public class ChildTestConfiguration { return Mockito.mock(ClusterDao.class); } + @Bean + public HostDao hostDao() { + return Mockito.mock(HostDao.class); + } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7e61e200/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java index 72ad834..70b5b93 100644 --- a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java +++ b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java @@ -12,10 +12,12 @@ import javax.inject.Inject; 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.HostEntity; import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity; import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity; import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.ClusterDao; import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao; +import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.HostDao; import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.HostPodDao; import org.apache.cloudstack.engine.service.api.ProvisioningService; import org.junit.Before; @@ -28,6 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.apache.cloudstack.engine.datacenter.entity.api.db.ClusterVO; import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO; import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO; +import org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO; import com.cloud.dc.DataCenter.NetworkType; @@ -49,6 +52,8 @@ public class ProvisioningTest extends TestCase { @Inject ClusterDao _clusterDao; + @Inject + HostDao _hostDao; @Before public void setUp() { @@ -63,7 +68,12 @@ public class ProvisioningTest extends TestCase { ClusterVO cluster = new ClusterVO(); Mockito.when(_clusterDao.findByUUID(Mockito.anyString())).thenReturn(cluster); - Mockito.when(_clusterDao.persist((ClusterVO) Mockito.anyObject())).thenReturn(cluster); + Mockito.when(_clusterDao.persist((ClusterVO) Mockito.anyObject())).thenReturn(cluster); + + HostVO host = new HostVO("68765876598"); + Mockito.when(_hostDao.findByUUID(Mockito.anyString())).thenReturn(host); + Mockito.when(_hostDao.persist((HostVO) Mockito.anyObject())).thenReturn(host); + } private void registerAndEnableZone() { @@ -90,12 +100,21 @@ public class ProvisioningTest extends TestCase { boolean result = cluster.enable(); System.out.println("result:"+result); } + + private void registerAndEnableHost() { + HostEntity host = service.registerHost("1265476542", "lab","owner", null, new HashMap<String, String>()); + State state = host.getState(); + System.out.println("state:"+state); + boolean result = host.enable(); + System.out.println("result:"+result); + } @Test public void testProvisioning() { - registerAndEnableZone(); - registerAndEnablePod(); - registerAndEnableCluster(); + //registerAndEnableZone(); + //registerAndEnablePod(); + //registerAndEnableCluster(); + registerAndEnableHost(); }
