Updated Branches: refs/heads/4.2-forward e34c80398 -> fe5468881
Add disassocating profile to UCS Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/fe546888 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/fe546888 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/fe546888 Branch: refs/heads/4.2-forward Commit: fe5468881a37a63f2218ea301acc684c53d0d722 Parents: e34c803 Author: frank <frank.zh...@citrix.com> Authored: Fri Sep 13 22:27:46 2013 -0700 Committer: frank <frank.zh...@citrix.com> Committed: Sat Sep 14 09:17:30 2013 -0700 ---------------------------------------------------------------------- api/src/com/cloud/event/EventTypes.java | 1 + client/tomcatconf/commands.properties.in | 1 + plugins/hypervisors/ucs/pom.xml | 5 ++ .../src/com/cloud/ucs/manager/UcsCommands.java | 31 ++++++++-- .../com/cloud/ucs/manager/UcsHttpClient.java | 7 ++- .../src/com/cloud/ucs/manager/UcsManager.java | 2 + .../com/cloud/ucs/manager/UcsManagerImpl.java | 50 +++++++++++++--- .../src/com/cloud/ucs/structure/UcsProfile.java | 0 .../api/DisassociateUcsProfileCmd.java | 61 ++++++++++++++++++++ 9 files changed, 144 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/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 ff59674..dc20400 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -443,6 +443,7 @@ public class EventTypes { public static final String EVENT_CLEANUP_VM_RESERVATION = "VM.RESERVATION.CLEANUP"; public static final String EVENT_UCS_ASSOCIATED_PROFILE = "UCS.ASSOCIATEPROFILE"; + public static final String EVENT_UCS_DISASSOCIATED_PROFILE = "UCS.DISASSOCIATEPROFILE"; static { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/client/tomcatconf/commands.properties.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 69a3120..492661e 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -618,6 +618,7 @@ listUcsProfiles=1 listUcsBlades=1 associateUcsProfileToBlade=1 deleteUcsManager=1 +disassociateUcsProfileFromBlade=1 #### New Load Balancer commands createLoadBalancer=15 http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/plugins/hypervisors/ucs/pom.xml ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ucs/pom.xml b/plugins/hypervisors/ucs/pom.xml index 24bdc94..fe89d26 100755 --- a/plugins/hypervisors/ucs/pom.xml +++ b/plugins/hypervisors/ucs/pom.xml @@ -52,5 +52,10 @@ <artifactId>cloud-api</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java old mode 100644 new mode 100755 index c0753f4..52e5edf --- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java +++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java @@ -67,6 +67,29 @@ public class UcsCommands { return cmd.toString(); } + public static String disassociateProfileFromBlade(String cookie, String profileDn) { + XmlObject cmd = new XmlObject("configConfMo"); + cmd.putElement("cookie", cookie); + cmd.putElement("inHierarchical", "false") + .putElement("inConfig", new XmlObject("inConfig") + .putElement("lsServer", new XmlObject("lsServer") + .putElement("dn", profileDn).putElement("lsBinding", new XmlObject("lsBinding").putElement("rn", "pn").putElement("status", "deleted")) + ) + ); + + return cmd.dump(); + } + + public static String deleteProfile(String cookie, String profileDn) { + XmlObject cmd = new XmlObject("configConfMos"); + cmd.putElement("cookie", cookie); + cmd.putElement("inHierarchical", "true") + .putElement("inConfigs", new XmlObject("inConfigs").putElement("pair", new XmlObject("pair").putElement("key", profileDn) + .putElement("lsServer", new XmlObject("lsServer").putElement("dn", profileDn).putElement("status", "deleted")) + )); + return cmd.dump(); + } + public static String associateProfileToBlade(String cookie, String profileDn, String bladeDn) { XmlObject cmd = new XmlObject("configConfMos").putElement("cookie", cookie).putElement("inHierarchical", "true").putElement( "inConfigs", new XmlObject("inConfigs").putElement( @@ -95,10 +118,10 @@ public class UcsCommands { .putElement("uuid", "") .putElement("vconProfileName", "") .putElement("lsBinding", new XmlObject("lsBinding") - .putElement("pnDn", bladeDn) - .putElement("restrictMigration", "no") - .putElement("rn", "pn") - ) + .putElement("pnDn", bladeDn) + .putElement("restrictMigration", "no") + .putElement("rn", "pn") + ) ) ) ); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java old mode 100644 new mode 100755 index 945d921..7758c4c --- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java +++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java @@ -19,6 +19,7 @@ package com.cloud.ucs.manager; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; import org.apache.commons.httpclient.methods.PostMethod; @@ -28,10 +29,14 @@ import org.apache.commons.httpclient.protocol.Protocol; import com.cloud.utils.exception.CloudRuntimeException; public class UcsHttpClient { - private static HttpClient client = new HttpClient(); + private static HttpClient client; private static Protocol ucsHttpsProtocol = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443); private final String url; + static { + client = new HttpClient(); + } + public UcsHttpClient(String ip) { url = String.format("http://%s/nuova", ip); Protocol.registerProtocol("https", ucsHttpsProtocol); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java index 0833e31..babec3a 100755 --- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java +++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java @@ -42,4 +42,6 @@ public interface UcsManager extends Manager, PluggableService { ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd); void deleteUcsManager(Long id); + + UcsBladeResponse disassociateProfile(Long bladeId); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java index 4aec48c..05b1214 100755 --- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java +++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java @@ -30,17 +30,12 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.cloudstack.api.AddUcsManagerCmd; -import org.apache.cloudstack.api.AssociateUcsProfileToBladeCmd; -import org.apache.cloudstack.api.ListUcsBladeCmd; -import org.apache.cloudstack.api.ListUcsManagerCmd; -import org.apache.cloudstack.api.ListUcsProfileCmd; +import org.apache.cloudstack.api.*; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.UcsBladeResponse; import org.apache.cloudstack.api.response.UcsManagerResponse; import org.apache.cloudstack.api.response.UcsProfileResponse; -import org.apache.log4j.Logger; -import org.apache.cloudstack.api.DeleteUcsManagerCmd; +import org.apache.log4j.Logger; import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; @@ -296,7 +291,14 @@ public class UcsManagerImpl implements UcsManager { UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl()); String res = client.call(cmd); List<UcsProfile> profiles = UcsProfile.fromXmlString(res); - return profiles; + List<UcsProfile> unassociated = new ArrayList<UcsProfile>(); + for (UcsProfile p : profiles) { + if (isProfileAssociated(mgrvo.getId(), p.getDn())) { + continue; + } + unassociated.add(p); + } + return unassociated; } @Override @@ -324,6 +326,7 @@ public class UcsManagerImpl implements UcsManager { return xo.get("outConfig.lsServer.dn"); } + private boolean isProfileAssociated(Long ucsMgrId, String dn) { UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId); UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl()); @@ -331,6 +334,17 @@ public class UcsManagerImpl implements UcsManager { String cmd = UcsCommands.configResolveDn(cookie, dn); String res = client.call(cmd); XmlObject xo = XmlObjectParser.parseFromString(res); + + return xo.get("outConfig.lsServer.assocState").equals("associated"); + } + + private boolean isBladeAssociated(Long ucsMgrId, String dn) { + UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId); + UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl()); + String cookie = getCookie(ucsMgrId); + String cmd = UcsCommands.configResolveDn(cookie, dn); + String res = client.call(cmd); + XmlObject xo = XmlObjectParser.parseFromString(res); s_logger.debug(String.format("association response is %s", res)); if (xo.get("outConfig.computeBlade.association").equals("none")) { @@ -363,7 +377,7 @@ public class UcsManagerImpl implements UcsManager { int count = 0; int timeout = 600; while (count < timeout) { - if (isProfileAssociated(mgrvo.getId(), bvo.getDn())) { + if (isBladeAssociated(mgrvo.getId(), bvo.getDn())) { break; } @@ -504,6 +518,7 @@ public class UcsManagerImpl implements UcsManager { cmds.add(AddUcsManagerCmd.class); cmds.add(AssociateUcsProfileToBladeCmd.class); cmds.add(DeleteUcsManagerCmd.class); + cmds.add(DisassociateUcsProfileCmd.class); return cmds; } @@ -517,4 +532,21 @@ public class UcsManagerImpl implements UcsManager { } ucsDao.remove(id); } + + @Override + public UcsBladeResponse disassociateProfile(Long bladeId) { + UcsBladeVO blade = bladeDao.findById(bladeId); + UcsManagerVO mgrvo = ucsDao.findById(blade.getUcsManagerId()); + UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl()); + String cookie = getCookie(mgrvo.getId()); + String cmd = UcsCommands.disassociateProfileFromBlade(cookie, blade.getProfileDn()); + client.call(cmd); + cmd = UcsCommands.deleteProfile(cookie, blade.getProfileDn()); + client = new UcsHttpClient(mgrvo.getUrl()); + client.call(cmd); + blade.setProfileDn(null); + bladeDao.update(blade.getId(), blade); + UcsBladeResponse rsp = bladeVOToResponse(blade); + return rsp; + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsProfile.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsProfile.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/structure/UcsProfile.java old mode 100644 new mode 100755 http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe546888/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/DisassociateUcsProfileCmd.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/DisassociateUcsProfileCmd.java b/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/DisassociateUcsProfileCmd.java new file mode 100755 index 0000000..ed20989 --- /dev/null +++ b/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/DisassociateUcsProfileCmd.java @@ -0,0 +1,61 @@ +package org.apache.cloudstack.api; + +import com.cloud.event.EventTypes; +import com.cloud.exception.*; +import com.cloud.ucs.manager.UcsManager; +import com.cloud.user.Account; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.api.response.UcsBladeResponse; +import org.apache.log4j.Logger; + +import javax.inject.Inject; + +/** + * Created with IntelliJ IDEA. + * User: frank + * Date: 9/13/13 + * Time: 6:23 PM + * To change this template use File | Settings | File Templates. + */ +@APICommand(name="disassociateUcsProfileFromBlade", description="disassociate a profile from a blade", responseObject=UcsBladeResponse.class) +public class DisassociateUcsProfileCmd extends BaseAsyncCmd { + private static Logger logger = Logger.getLogger(DisassociateUcsProfileCmd.class); + + @Inject + private UcsManager mgr; + + @Parameter(name=ApiConstants.UCS_BLADE_ID, type=CommandType.UUID, entityType=UcsBladeResponse.class, description="blade id", required=true) + private Long bladeId; + + @Override + public String getEventType() { + return EventTypes.EVENT_UCS_DISASSOCIATED_PROFILE; + } + + @Override + public String getEventDescription() { + return "disassociate a profile from blade"; + } + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + UcsBladeResponse rsp = mgr.disassociateProfile(bladeId); + rsp.setResponseName(getCommandName()); + this.setResponseObject(rsp); + } catch(Exception e) { + logger.warn(e.getMessage(), e); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } + } + + @Override + public String getCommandName() { + return "disassociateucsprofilefrombladeresponse"; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +}