incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [32/35] git commit: refs/heads/ui-multiple-nics - baremetal: Remove old templateadapter in cloud-server, fix spring xmls
Date Wed, 13 Mar 2013 17:13:56 GMT
baremetal: Remove old templateadapter in cloud-server, fix spring xmls

The BareMetalTemplateAdapter in cloud-server is old and was introduced by recent
branch merges, Frank had separated and moved code to the baremetal plugin so
we will use that.

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/0f8c4d0a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/0f8c4d0a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/0f8c4d0a

Branch: refs/heads/ui-multiple-nics
Commit: 0f8c4d0ac09d476b4650c92d26bfb5c2ff4fa5e6
Parents: 1f28e64
Author: Rohit Yadav <bhaisaab@apache.org>
Authored: Wed Mar 13 11:49:25 2013 +0530
Committer: Rohit Yadav <bhaisaab@apache.org>
Committed: Wed Mar 13 11:50:54 2013 +0530

----------------------------------------------------------------------
 client/tomcatconf/componentContext.xml.in          |    6 +-
 client/tomcatconf/nonossComponentContext.xml.in    |    6 +-
 .../cloud/baremetal/BareMetalTemplateAdapter.java  |  217 ---------------
 3 files changed, 2 insertions(+), 227 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0f8c4d0a/client/tomcatconf/componentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in
index 23566e2..7b64f49 100644
--- a/client/tomcatconf/componentContext.xml.in
+++ b/client/tomcatconf/componentContext.xml.in
@@ -107,11 +107,7 @@
   
   <bean id="hypervisorTemplateAdapter" class="com.cloud.template.HypervisorTemplateAdapter">
     <property name="name" value="HypervisorAdapter"/>
-  </bean> 
-  
-   <bean id="bareMetalTemplateAdapter" class="com.cloud.baremetal.BareMetalTemplateAdapter">
-    <property name="name" value="BareMetalAdapter"/>
-  </bean> 
+  </bean>
   
   <!--
     Storage pool allocators

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0f8c4d0a/client/tomcatconf/nonossComponentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/nonossComponentContext.xml.in b/client/tomcatconf/nonossComponentContext.xml.in
index 20e0c32..7e3552d 100644
--- a/client/tomcatconf/nonossComponentContext.xml.in
+++ b/client/tomcatconf/nonossComponentContext.xml.in
@@ -113,11 +113,7 @@
   
   <bean id="hypervisorTemplateAdapter" class="com.cloud.template.HypervisorTemplateAdapter">
     <property name="name" value="HypervisorAdapter"/>
-  </bean> 
-  
-   <bean id="bareMetalTemplateAdapter" class="com.cloud.baremetal.BareMetalTemplateAdapter">
-    <property name="name" value="BareMetalAdapter"/>
-  </bean> 
+  </bean>
   
   <!--
     Storage pool allocators

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0f8c4d0a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java b/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
deleted file mode 100755
index d902dc4..0000000
--- a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
+++ /dev/null
@@ -1,217 +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.baremetal;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-
-import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
-import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
-import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.configuration.Resource.ResourceType;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.event.EventTypes;
-import com.cloud.event.UsageEventUtils;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.host.Host;
-import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDao;
-import com.cloud.resource.ResourceManager;
-import com.cloud.storage.TemplateProfile;
-import com.cloud.storage.VMTemplateHostVO;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.storage.VMTemplateZoneVO;
-import com.cloud.template.TemplateAdapter;
-import com.cloud.template.TemplateAdapterBase;
-import com.cloud.user.Account;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-@Local(value=TemplateAdapter.class)
-public class BareMetalTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter
{
-	private final static Logger s_logger = Logger.getLogger(BareMetalTemplateAdapter.class);
-	@Inject HostDao _hostDao;
-	@Inject ResourceManager _resourceMgr;
-
-	@Override
-    public String getName() {
-        return TemplateAdapterType.BareMetal.getName();
-    }
-
-	@Override
-	public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException
{
-		TemplateProfile profile = super.prepare(cmd);
-
-		if (profile.getZoneId() == null || profile.getZoneId() == -1) {
-			List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
-			for (DataCenterVO dc : dcs) {
-				List<HostVO> pxeServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer,
dc.getId());
-				if (pxeServers.size() == 0) {
-					throw new CloudRuntimeException("Please add PXE server before adding baremetal template
in zone " + dc.getName());
-				}
-			}
-		} else {
-			List<HostVO> pxeServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer,
profile.getZoneId());
-			if (pxeServers.size() == 0) {
-				throw new CloudRuntimeException("Please add PXE server before adding baremetal template
in zone " + profile.getZoneId());
-			}
-		}
-
-		return profile;
-	}
-
-	@Override
-	public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
-		throw new CloudRuntimeException("Baremetal doesn't support ISO template");
-	}
-
-	private void templateCreateUsage(VMTemplateVO template, HostVO host) {
-		if (template.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
-            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_TEMPLATE_CREATE, template.getAccountId(),
host.getDataCenterId(),
-                    template.getId(), template.getName(), null, template.getSourceTemplateId(),
0L,
-                    template.getClass().getName(), template.getUuid());
-		}
-	}
-
-	@Override
-	public VMTemplateVO create(TemplateProfile profile) {
-		VMTemplateVO template = persistTemplate(profile);
-		Long zoneId = profile.getZoneId();
-
-		/* There is no secondary storage vm for baremetal, we use pxe server id.
-		 * Tempalte is not bound to pxeserver right now, and we assume the pxeserver
-		 * cannot be removed once it was added. so we use host id of first found pxe
-		 * server as reference in template_host_ref.
-		 * This maybe a FIXME in future.
-		 */
-		VMTemplateHostVO vmTemplateHost = null;
-		if (zoneId == null || zoneId == -1) {
-			List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
-			for (DataCenterVO dc : dcs) {
-				HostVO pxe = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer, dc.getId()).get(0);
-
-				vmTemplateHost = _tmpltHostDao.findByHostTemplate(dc.getId(), template.getId());
-				if (vmTemplateHost == null) {
-					vmTemplateHost = new VMTemplateHostVO(pxe.getId(), template.getId(), new Date(), 100,
-							Status.DOWNLOADED, null, null, null, null, template.getUrl());
-					_tmpltHostDao.persist(vmTemplateHost);
-					templateCreateUsage(template, pxe);
-				}
-			}
-		} else {
-			HostVO pxe = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer, zoneId).get(0);
-			vmTemplateHost = new VMTemplateHostVO(pxe.getId(), template.getId(), new Date(), 100,
-					Status.DOWNLOADED, null, null, null, null, template.getUrl());
-			_tmpltHostDao.persist(vmTemplateHost);
-			templateCreateUsage(template, pxe);
-		}
-
-		_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
-		return template;
-	}
-
-	public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
-		throw new CloudRuntimeException("Baremetal doesn't support ISO, how the delete get here???");
-	}
-
-	@Override @DB
-	public boolean delete(TemplateProfile profile) {
-		VMTemplateVO template = (VMTemplateVO)profile.getTemplate();
-    	Long templateId = template.getId();
-    	boolean success = true;
-    	String zoneName;
-    	boolean isAllZone;
-
-    	if (!template.isCrossZones() && profile.getZoneId() != null) {
-    		isAllZone = false;
-    		zoneName = profile.getZoneId().toString();
-    	} else {
-    		zoneName = "all zones";
-    		isAllZone = true;
-    	}
-
-    	s_logger.debug("Attempting to mark template host refs for template: " + template.getName()
+ " as destroyed in zone: " + zoneName);
-    	Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
-    	String eventType = EventTypes.EVENT_TEMPLATE_DELETE;
-    	List<VMTemplateHostVO> templateHostVOs = _tmpltHostDao.listByTemplateId(templateId);
-
-		for (VMTemplateHostVO vo : templateHostVOs) {
-			VMTemplateHostVO lock = null;
-			try {
-				HostVO pxeServer = _hostDao.findById(vo.getHostId());
-				if (!isAllZone && pxeServer.getDataCenterId() != profile.getZoneId()) {
-					continue;
-				}
-
-				lock = _tmpltHostDao.acquireInLockTable(vo.getId());
-				if (lock == null) {
-					s_logger.debug("Failed to acquire lock when deleting templateHostVO with ID: " + vo.getId());
-					success = false;
-					break;
-				}
-
-				vo.setDestroyed(true);
-				_tmpltHostDao.update(vo.getId(), vo);
-				VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(pxeServer.getDataCenterId(),
templateId);
-				if (templateZone != null) {
-					_tmpltZoneDao.remove(templateZone.getId());
-				}
-
-                UsageEventUtils.publishUsageEvent(eventType, account.getId(), pxeServer.getDataCenterId(),
-                        templateId, null, template.getClass().getName(), template.getUuid());
-			} finally {
-				if (lock != null) {
-					_tmpltHostDao.releaseFromLockTable(lock.getId());
-				}
-			}
-		}
-
-    	s_logger.debug("Successfully marked template host refs for template: " + template.getName()
+ " as destroyed in zone: " + zoneName);
-
-    	// If there are no more non-destroyed template host entries for this template, delete
it
-		if (success && (_tmpltHostDao.listByTemplateId(templateId).size() == 0)) {
-			long accountId = template.getAccountId();
-
-			VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);
-
-			try {
-				if (lock == null) {
-					s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId);
-					success = false;
-				} else if (_tmpltDao.remove(templateId)) {
-					// Decrement the number of templates
-				    _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
-				}
-
-			} finally {
-				if (lock != null) {
-					_tmpltDao.releaseFromLockTable(lock.getId());
-				}
-			}
-			s_logger.debug("Removed template: " + template.getName() + " because all of its template
host refs were marked as destroyed.");
-		}
-
-    	return success;
-	}
-}


Mime
View raw message