Package org.wso2.carbon.cloud.csg.agent.client

Source Code of org.wso2.carbon.cloud.csg.agent.client.CSGAdminClient

/*
* Copyright WSO2, Inc. (http://wso2.com)
*
* 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.
*/
package org.wso2.carbon.cloud.csg.agent.client;

import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.cloud.csg.stub.CSGAdminServiceCSGException;
import org.wso2.carbon.cloud.csg.stub.CSGAdminServiceStub;
import org.wso2.carbon.cloud.csg.stub.types.common.ServiceMetaData;

import java.rmi.RemoteException;
import java.util.Locale;


/**
* <code>CSGAdminClient </code> provides the admin client for CSGAdmin service
*/
public  class CSGAdminClient {

    private static final Log log = LogFactory.getLog(CSGAdminClient.class);

    private CSGAdminServiceStub stub;


    public CSGAdminClient(String cookie, String backendServerUrl ) throws AxisFault{
        String serviceURL = backendServerUrl + "CSGAdminService";
        stub = new CSGAdminServiceStub(serviceURL);
        Options options = stub._getServiceClient().getOptions();
        options.setManageSession(true);
        options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
    }

    public CSGAdminClient(String cookie,
                          String backendServerURL,
                          ConfigurationContext configCtx) throws AxisFault {
        String serviceURL = backendServerURL + "CSGAdminService";
        stub = new CSGAdminServiceStub(configCtx, serviceURL);
        Options options = stub._getServiceClient().getOptions();
        options.setManageSession(true);
        options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
    }

    /**
     * Deploy the proxy
     * @param serviceMetaData provides the metadata associated with the service
     * @throws AxisFault throws in case of an error
     */
    public void deployProxy(ServiceMetaData serviceMetaData) throws AxisFault{
        try {
            stub.deployProxy(serviceMetaData);
        } catch (RemoteException e) {
            handleException("Error occurs while deploying the proxy '" +
                    serviceMetaData.getServiceName() + "'", e);
        } catch (CSGAdminServiceCSGException e){
            handleException("Cloud not deploy the proxy '" + serviceMetaData.getServiceName() +
                    "'", e);
        }
    }

    /**
     * Un-deploy the proxy
     * @param serviceName meta data associated with the data
     * @throws AxisFault throws in case of an error
     */
    public void unDeployProxy(String serviceName) throws AxisFault{
        try {
            stub.unDeployProxy(serviceName);
        } catch (RemoteException e) {
            handleException("Error occurs while undeploying the proxy '" + serviceName + "'", e);
        } catch (CSGAdminServiceCSGException e) {
            handleException("Cloud not undeploy the proxy '" + serviceName + "'", e);
        }
    }

    /**
     * Get the remote connection url of qpid broker
     * @return the connection url
     * @throws AxisFault throws in case of an error
     */
    public String getRemoteConnectionURL() throws AxisFault{
        try {
            return stub.getRemoteConnectionURL();
        } catch (RemoteException e) {
            handleException("Cloud not get the remote connection URL", e);
        }
        return null;
    }

    /**
     * Create the jndi property file required by Qpid client libraries
     * @param qpidJNDIString Qpid connection string
     * @param domain the domain name
     * @throws AxisFault
     */
    public void createServerQpidJNDIFile(String qpidJNDIString, String domain) throws AxisFault{
        try {
            stub.createOrUpdateServerQpidJNDIFile(qpidJNDIString, domain);
        } catch (RemoteException e) {
            handleException("Error occurs while updating the JNDI string " + qpidJNDIString + "'",
                    e);
        } catch (CSGAdminServiceCSGException e) {
            handleException("Cloud not update the property file", e);
        }
    }

    public void createOrUpdateServerRegistryJNDI(String qpidJNDIString) throws AxisFault{
        try {
            stub.createOrUpdateServerRegistryJNDI(qpidJNDIString);
        } catch (RemoteException e) {
            handleException("Error occurs while updating the JNDI string " + qpidJNDIString + "'",
                    e);
        } catch (CSGAdminServiceCSGException e) {
            handleException("Cloud not update the registry JNDI entry", e);
        }
    }

    private void handleException(String msg, Throwable t) throws AxisFault {
        log.error(msg, t);
        throw new AxisFault(msg, t);
    }
}
TOP

Related Classes of org.wso2.carbon.cloud.csg.agent.client.CSGAdminClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.