def __get_my_container_info(self):
        metadata_manager = MetadataAPI()
        current_container = {}
        current_container["name"] = metadata_manager.get_container_name()
        current_container["ip"] = metadata_manager.get_container_ip()
        current_container["id"] = metadata_manager.get_container_create_index()

        return current_container
Exemplo n.º 2
0
  def __get_my_container_info(self):
    metadata_manager = MetadataAPI()
    current_container = {}
    current_container["name"] = metadata_manager.get_container_name()
    current_container["ip"] = metadata_manager.get_container_ip()
    current_container["id"] = metadata_manager.get_container_create_index()

    return current_container
Exemplo n.º 3
0
  def __get_other_container_in_service(self, my_name):
    metadata_manager = MetadataAPI()
    list_containers = {}
    metadata_manager.wait_service_containers()
    list_containers_name = metadata_manager.get_service_containers()
    for container_name in list_containers_name:
        if container_name != my_name:
            list_containers[container_name] = {}
            list_containers[container_name]['id'] = metadata_manager.get_container_create_index(container_name)
            list_containers[container_name]['name'] = container_name
            list_containers[container_name]['ip'] = metadata_manager.get_container_ip(container_name)


    return list_containers
Exemplo n.º 4
0
    def __get_other_container_in_service(self, my_name):
        metadata_manager = MetadataAPI()
        list_containers = {}
        metadata_manager.wait_service_containers()
        list_containers_name = metadata_manager.get_service_containers()
        for container_name in list_containers_name:
            if container_name != my_name:
                list_containers[container_name] = {}
                list_containers[container_name][
                    'id'] = metadata_manager.get_container_create_index(
                        container_name)
                list_containers[container_name]['name'] = container_name
                list_containers[container_name][
                    'ip'] = metadata_manager.get_container_ip(container_name)

        return list_containers
Exemplo n.º 5
0
  def __set_tomcat_cluster(self):
    global TOMCAT_PATH

    metadata_manager = MetadataAPI()

    # I check there are more than 1 container
    number_node = metadata_manager.get_service_scale_size()
    if number_node < 2 :
        print("No cluster setting needed")
        return True




    print("We will setting Tomcat cluster with " + str(number_node) + " instances")

    # I get my container info
    my_name = metadata_manager.get_container_name()
    my_ip = metadata_manager.get_container_ip()
    my_id = metadata_manager.get_container_create_index()

    # I get the other container info
    list_containers = {}
    list_containers_name = metadata_manager.get_service_containers()
    first_container = True
    for container_name in list_containers_name:
        if container_name != my_name:
            list_containers[container_name] = {}
            list_containers[container_name]['id'] = metadata_manager.get_container_create_index(container_name)
            list_containers[container_name]['name'] = container_name
            list_containers[container_name]['ip'] = metadata_manager.get_container_ip(container_name)
            if list_containers[container_name]['ip'] is None or list_containers[container_name]['ip'] == '':
                print("The container " + container_name + " have not yet the IP. We stay it")
                return False

            if list_containers[container_name]['id'] < my_id:
                first_container = False

    # If I am not the first container, I wait some times that the first start
    #if first_container is False:
    #    print("I wait 300s that the first container run before start (issue about cluster)")
    #    time.sleep(300)

    # We set the engine name
    #self.replace_all(TOMCAT_PATH + '/conf/server.xml', re.escape('<Engine name="Catalina" defaultHost="localhost">'), '<Engine name="Catalina" defaultHost="localhost" jvmRoute="' + my_name + '">')

    # We set the cluster
    cluster_setting = '''
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6" channelStartOptions="3">

        <Channel className="org.apache.catalina.tribes.group.GroupChannel">

            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" autoBind="9" selectorTimeout="5000" maxThreads="6" address="''' + my_ip + '''" port="4444" />
                <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                    <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
                </Sender>
		<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">'''

    for container in list_containers.itervalues():
        cluster_setting += '<Member className="org.apache.catalina.tribes.membership.StaticMember" securePort="-1" domain="cluster" host="' + container['ip'] + '" port="4444" uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,' + str(container['id']) + '}"/>'
    cluster_setting += '''
                </Interceptor>
        </Channel>
        <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" />
        <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
        <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>

        <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    		tempDir="/tmp/war-temp/"
                    		deployDir="/tmp/war-deploy/"
                    		watchDir="/tmp/war-listen/"
                    		watchEnabled="false"/>

    </Cluster>
    '''
    self.replace_all(TOMCAT_PATH + '/conf/server.xml', re.escape('</Host>'), cluster_setting + "\n" + '</Host>')

    self.replace_all(TOMCAT_PATH + '/conf/context.xml', re.escape('</Context>'), '<Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" /></Context>')

    return True