/** * */ package org.opennaas.extensions.vcpe.capability.builder.builders.helpers; /* * #%L * OpenNaaS :: vCPENetwork * %% * 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.IResource; import org.opennaas.core.resources.IResourceManager; import org.opennaas.core.resources.ResourceException; import org.opennaas.core.resources.protocol.IProtocolManager; import org.opennaas.core.resources.protocol.ProtocolException; import org.opennaas.core.resources.queue.QueueResponse; import org.opennaas.extensions.queuemanager.IQueueManagerCapability; import org.opennaas.extensions.vcpe.Activator; /** * @author Jordi * */ public class GenericHelper { /** * @return * @throws ResourceException */ public static IResourceManager getResourceManager() throws ResourceException { try { return Activator.getResourceManagerService(); } catch (ActivatorException e) { throw new ResourceException("Could not find ResourceManager", e); } } /** * @return * @throws ResourceException */ public static IProtocolManager getProtocolManager() throws ResourceException { try { return Activator.getProtocolManagerService(); } catch (ActivatorException e) { throw new ResourceException("Could not find ProtocolManager", e); } } /** * Execute the queue of the resource * * @param vcpe * @throws ResourceException * @throws ProtocolException */ public static void executeQueue(IResource vcpe) throws ResourceException, ProtocolException { IQueueManagerCapability qCapability = (IQueueManagerCapability) vcpe.getCapabilityByInterface(IQueueManagerCapability.class); QueueResponse response = qCapability.execute(); if (!response.isOk()) { String commitMsg = response.getConfirmResponse().getInformation(); throw new ResourceException( "Failed to execute queue for resource " + vcpe.getResourceDescriptor().getInformation().getName() + ": " + commitMsg); } } }