package org.opennaas.extensions.router.capability.bgp; /* * #%L * OpenNaaS :: Router :: BGP Capability * %% * Copyright (C) 2007 - 2014 FundaciĆ³ Privada i2CAT, Internet i InnovaciĆ³ a Catalunya * %% * Licensed 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. * #L% */ import org.opennaas.core.resources.ActivatorException; import org.opennaas.core.resources.action.IAction; import org.opennaas.core.resources.action.IActionSet; import org.opennaas.core.resources.capability.AbstractCapability; import org.opennaas.core.resources.capability.CapabilityException; import org.opennaas.core.resources.descriptor.CapabilityDescriptor; import org.opennaas.core.resources.descriptor.ResourceDescriptorConstants; import org.opennaas.extensions.queuemanager.IQueueManagerCapability; import org.opennaas.extensions.router.model.ComputerSystem; public class BGPCapability extends AbstractCapability implements IBGPCapability { public static final String CAPABILITY_TYPE = "bgp"; private String resourceId = ""; public BGPCapability(CapabilityDescriptor capabilityDescriptor, String resourceId) { super(capabilityDescriptor); this.resourceId = resourceId; } /* * (non-Javadoc) * * @see org.opennaas.core.resources.caactivatepability.AbstractCapability#activate() */ @Override public void activate() throws CapabilityException { registerService(Activator.getContext(), CAPABILITY_TYPE, getResourceType(), getResourceName(), IBGPCapability.class.getName()); super.activate(); } /* * (non-Javadoc) * * @see org.opennaas.core.resources.capability.AbstractCapability#deactivate() */ @Override public void deactivate() throws CapabilityException { unregisterService(); super.deactivate(); } @Override public String getCapabilityName() { return CAPABILITY_TYPE; } @Override public IActionSet getActionSet() throws CapabilityException { String actionSetName = this.descriptor.getPropertyValue(ResourceDescriptorConstants.ACTION_NAME); String actionSetVersion = this.descriptor.getPropertyValue(ResourceDescriptorConstants.ACTION_VERSION); try { return Activator.getActionSetService(getCapabilityName(), actionSetName, actionSetVersion); } catch (ActivatorException e) { throw new CapabilityException(e); } } /* * (non-Javadoc) * * @see org.opennaas.core.resources.capability.AbstractCapability#queueAction(org.opennaas.core.resources.action.IAction) */ @Override public void queueAction(IAction action) throws CapabilityException { getQueueManager(resourceId).queueAction(action); } /** * * @return QueuemanagerService this capability is associated to (the one of the resource it belongs to). * @throws CapabilityException * if desired queueManagerService could not be retrieved. */ private IQueueManagerCapability getQueueManager(String resourceId) throws CapabilityException { try { return Activator.getQueueManagerService(resourceId); } catch (ActivatorException e) { throw new CapabilityException("Failed to get QueueManagerService for resource " + resourceId, e); } } @Override public void configureBGP(ComputerSystem systemWithBGPAndPolicies) throws CapabilityException { IAction action = createActionAndCheckParams(BGPActionSet.CONFIGURE_BGP, systemWithBGPAndPolicies); queueAction(action); } @Override public void unconfigureBGP(ComputerSystem systemWithBGPAndPolicies) throws CapabilityException { IAction action = createActionAndCheckParams(BGPActionSet.UNCONFIGURE_BGP, systemWithBGPAndPolicies); queueAction(action); } }