Repository: cloudstack Updated Branches: refs/heads/master 95b9be0cb -> 2ae40237a
CLOUDSTACK-7795 Fix multiple baremetal rct configuraitons Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2ae40237 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2ae40237 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2ae40237 Branch: refs/heads/master Commit: 2ae40237a4e867b4f6955080dc8e96e0080d99b5 Parents: 95b9be0 Author: Frank Zhang <frank.zh...@citrix.com> Authored: Mon Oct 27 15:13:45 2014 -0700 Committer: Frank Zhang <frank.zh...@citrix.com> Committed: Mon Oct 27 15:14:08 2014 -0700 ---------------------------------------------------------------------- api/src/com/cloud/event/EventTypes.java | 1 + .../baremetal/database/BaremetalRctVO.java | 5 +- .../baremetal/manager/BaremetalVlanManager.java | 5 +- .../manager/BaremetalVlanManagerImpl.java | 21 +++-- .../networkservice/BaremetalRctResponse.java | 3 + .../cloudstack/api/DeleteBaremetalRctCmd.java | 85 ++++++++++++++++++++ 6 files changed, 113 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ae40237/api/src/com/cloud/event/EventTypes.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index 3a1d58a..2e8c8ae 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -454,6 +454,7 @@ public class EventTypes { public static final String EVENT_BAREMETAL_PXE_SERVER_ADD = "PHYSICAL.PXE.ADD"; public static final String EVENT_BAREMETAL_PXE_SERVER_DELETE = "PHYSICAL.PXE.DELETE"; public static final String EVENT_BAREMETAL_RCT_ADD = "BAREMETAL.RCT.ADD"; + public static final String EVENT_BAREMETAL_RCT_DELETE = "BAREMETAL.RCT.DELETE"; public static final String EVENT_BAREMETAL_PROVISION_DONE = "BAREMETAL.PROVISION.DONE"; public static final String EVENT_AFFINITY_GROUP_CREATE = "AG.CREATE"; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ae40237/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java index 91cbc9f..3a24cf4 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/database/BaremetalRctVO.java @@ -17,6 +17,9 @@ // package com.cloud.baremetal.database; +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -30,7 +33,7 @@ import java.util.UUID; */ @Entity @Table(name = "baremetal_rct") -public class BaremetalRctVO { +public class BaremetalRctVO implements InternalIdentity, Identity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ae40237/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java index b2a1be9..76f1052 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManager.java @@ -18,13 +18,14 @@ package com.cloud.baremetal.manager; import com.cloud.baremetal.networkservice.BaremetalRctResponse; -import com.cloud.baremetal.networkservice.BaremetalSwitchBackend; +import com.cloud.baremetal.networkservice.BaremetalSwitchBackend; import com.cloud.deploy.DeployDestination; import com.cloud.network.Network; import com.cloud.utils.component.Manager; import com.cloud.utils.component.PluggableService; import com.cloud.vm.VirtualMachineProfile; import org.apache.cloudstack.api.AddBaremetalRctCmd; +import org.apache.cloudstack.api.DeleteBaremetalRctCmd; /** * Created by frank on 4/30/14. @@ -40,5 +41,7 @@ public interface BaremetalVlanManager extends Manager, PluggableService { void registerSwitchBackend(BaremetalSwitchBackend backend); + void deleteRct(DeleteBaremetalRctCmd cmd); + BaremetalRctResponse listRct(); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ae40237/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java index c8473b6..a77cf35 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java @@ -40,6 +40,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachineProfile; import com.google.gson.Gson; import org.apache.cloudstack.api.AddBaremetalRctCmd; +import org.apache.cloudstack.api.DeleteBaremetalRctCmd; import org.apache.cloudstack.api.ListBaremetalRctCmd; import org.apache.cloudstack.api.command.admin.user.RegisterCmd; import org.springframework.web.client.RestTemplate; @@ -69,20 +70,24 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl @Inject private AccountManager acntMgr; - private Map<String, BaremetalSwitchBackend> backends; + private Map<String, BaremetalSwitchBackend> backends; private class RackPair { BaremetalRct.Rack rack; BaremetalRct.HostEntry host; } - public void setBackends(Map<String, BaremetalSwitchBackend> backends) { - this.backends = backends; - } - + public void setBackends(Map<String, BaremetalSwitchBackend> backends) { + this.backends = backends; + } + @Override public BaremetalRctResponse addRct(AddBaremetalRctCmd cmd) { try { + List<BaremetalRctVO> existings = rctDao.listAll(); + if (!existings.isEmpty()) { + throw new CloudRuntimeException(String.format("there is some RCT existing. A CloudStack deployment accepts only one RCT")); + } URL url = new URL(cmd.getRctUrl()); RestTemplate rest = new RestTemplate(); String rctStr = rest.getForObject(url.toString(), String.class); @@ -172,6 +177,11 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl } @Override + public void deleteRct(DeleteBaremetalRctCmd cmd) { + rctDao.remove(cmd.getId()); + } + + @Override public BaremetalRctResponse listRct() { List<BaremetalRctVO> vos = rctDao.listAll(); if (!vos.isEmpty()) { @@ -218,6 +228,7 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl List<Class<?>> cmds = new ArrayList<Class<?>>(); cmds.add(AddBaremetalRctCmd.class); cmds.add(ListBaremetalRctCmd.class); + cmds.add(DeleteBaremetalRctCmd.class); return cmds; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ae40237/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java index cf85f19..d1577aa 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalRctResponse.java @@ -17,14 +17,17 @@ // package com.cloud.baremetal.networkservice; +import com.cloud.baremetal.database.BaremetalRctVO; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; /** * Created by frank on 5/8/14. */ +@EntityReference(value = BaremetalRctVO.class) public class BaremetalRctResponse extends BaseResponse { @SerializedName(ApiConstants.ID) @Param(description = "id of rct") http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2ae40237/plugins/hypervisors/baremetal/src/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/baremetal/src/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java b/plugins/hypervisors/baremetal/src/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java new file mode 100755 index 0000000..f1c8423 --- /dev/null +++ b/plugins/hypervisors/baremetal/src/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java @@ -0,0 +1,85 @@ +// 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.api; + +import com.cloud.baremetal.manager.BaremetalVlanManager; +import com.cloud.baremetal.networkservice.BaremetalRctResponse; +import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.log4j.Logger; + +import javax.inject.Inject; + +/** + * Created by frank on 10/27/14. + */ +@APICommand(name = "deleteBaremetalRct", description = "deletes baremetal rack configuration text", responseObject = SuccessResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) +public class DeleteBaremetalRctCmd extends BaseAsyncCmd { + private static final String s_name = "deletebaremetalrctresponse"; + public static final Logger s_logger = Logger.getLogger(DeleteBaremetalRctCmd.class); + + @Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, description = "RCT id", required = true, entityType = BaremetalRctResponse.class) + private Long id; + + @Inject + private BaremetalVlanManager vlanMgr; + + @Override + public String getEventType() { + return EventTypes.EVENT_BAREMETAL_RCT_DELETE; + } + + @Override + public String getEventDescription() { + return "Deleting baremetal rct configuration"; + } + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + vlanMgr.deleteRct(this); + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); + } catch (Exception e) { + s_logger.warn(String.format("unable to add baremetal RCT[%s]", getId()), e); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + public Long getId() { + return id; + } +}