Examples of ServerApi


Examples of com.dotcms.cluster.business.ServerAPI

      if(cacheProperties==null) {
        cacheProperties = new HashMap<String, String>();
      }
     
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      ServerAPI serverAPI = APILocator.getServerAPI();
     
      String cacheProtocol, bindAddr, bindPort, cacheTCPInitialHosts, mCastAddr, mCastPort, preferIPv4;
      if(Config.getBooleanProperty("CLUSTER_AUTOWIRE",true)) {
          Logger.info(this, "Using automatic port placement as CLUSTER_AUTOWIRE is ON");
         
          cacheProtocol = UtilMethods.isSet(cacheProperties.get("CACHE_PROTOCOL"))?cacheProperties.get("CACHE_PROTOCOL")
                      :Config.getStringProperty("CACHE_PROTOCOL", "tcp");
         
          String storedBindAddr = (UtilMethods.isSet(localServer.getHost()) && !localServer.getHost().equals("localhost"))
                      ?localServer.getHost():localServer.getIpAddress();
              bindAddr = UtilMethods.isSet(cacheProperties.get("BIND_ADDRESS"))?cacheProperties.get("BIND_ADDRESS")
                      :Config.getStringProperty("CACHE_BINDADDRESS", storedBindAddr );
             
              bindPort = UtilMethods.isSet(cacheProperties.get("CACHE_BINDPORT"))?cacheProperties.get("CACHE_BINDPORT")
                      :localServer!=null&&UtilMethods.isSet(localServer.getCachePort())?Long.toString(localServer.getCachePort())
                      :ClusterFactory.getNextAvailablePort(localServer.getServerId(), ServerPort.CACHE_PORT);
                     
                localServer.setCachePort(Integer.parseInt(bindPort));

                localServer.setHost(Config.getStringProperty("CACHE_BINDADDRESS", null));               

                List<String> myself = new ArrayList<String>();
                myself.add(localServer.getServerId());

                List<Server> aliveServers = serverAPI.getAliveServers(myself);
                aliveServers.add(localServer);

                StringBuilder initialHosts = new StringBuilder();

                int i=0;
                for (Server server : aliveServers) {
                    if(i>0) {
                        initialHosts.append(",");
                    }

                    if(UtilMethods.isSet(server.getHost()) && !server.getHost().equals("localhost")) {
                        initialHosts.append(server.getHost()).append("[").append(server.getCachePort()).append("]");
                    } else {
                        initialHosts.append(server.getIpAddress()).append("[").append(server.getCachePort()).append("]");
                    }
                    i++;
                }

                if(initialHosts.length()==0) {
                    if(bindAddr.equals("localhost")) {
                        initialHosts.append(localServer.getIpAddress()).append("[").append(bindPort).append("]");
                    } else {
                        initialHosts.append(bindAddr).append("[").append(bindPort).append("]");
                    }
                }

                cacheTCPInitialHosts = UtilMethods.isSet(cacheProperties.get("CACHE_TCP_INITIAL_HOSTS"))?cacheProperties.get("CACHE_TCP_INITIAL_HOSTS")
                        :Config.getStringProperty("CACHE_TCP_INITIAL_HOSTS", initialHosts.toString());

                mCastAddr = UtilMethods.isSet(cacheProperties.get("CACHE_MULTICAST_ADDRESS"))?cacheProperties.get("CACHE_MULTICAST_ADDRESS")
                        :Config.getStringProperty("CACHE_MULTICAST_ADDRESS", "228.10.10.10");
                mCastPort = UtilMethods.isSet(cacheProperties.get("CACHE_MULTICAST_PORT"))?cacheProperties.get("CACHE_MULTICAST_PORT")
                        :Config.getStringProperty("CACHE_MULTICAST_PORT", "45588");
                preferIPv4 = UtilMethods.isSet(cacheProperties.get("CACHE_FORCE_IPV4"))?cacheProperties.get("CACHE_FORCE_IPV4")
                        :Config.getStringProperty("CACHE_FORCE_IPV4", "true");
      }
      else {
          Logger.info(this, "Using manual port placement as CLUSTER_AUTOWIRE is OFF");
         
          cacheProtocol = Config.getStringProperty("CACHE_PROTOCOL", "tcp");
          bindAddr = Config.getStringProperty("CACHE_BINDADDRESS", null);
          bindPort = Config.getStringProperty("CACHE_BINDPORT", null);
          cacheTCPInitialHosts = Config.getStringProperty("CACHE_TCP_INITIAL_HOSTS", "localhost[7800]");
          mCastAddr = Config.getStringProperty("CACHE_MULTICAST_ADDRESS", "228.10.10.10");
          mCastPort = Config.getStringProperty("CACHE_MULTICAST_PORT", "45588");
          preferIPv4 = Config.getStringProperty("CACHE_FORCE_IPV4", "true");
      }

      String cacheFile = "cache-jgroups-" + cacheProtocol + ".xml";

      Logger.info(this, "***\t Going to load JGroups with this Classpath file " + cacheFile);

      if (UtilMethods.isSet(bindAddr)) {
          Logger.info(this, "***\t Using " + bindAddr + " as the bindaddress");
        System.setProperty("jgroups.bind_addr", bindAddr);
      }
      else {
                Logger.info(this, "***\t bindaddress is not set");
            }

      if (UtilMethods.isSet(bindPort)) {
          Logger.info(this, "***\t Using " + bindPort + " as the bindport");
        System.setProperty("jgroups.bind_port", bindPort);
      }
      else {
                Logger.info(this, "***\t bindport is not set");
            }
     
      if (cacheProtocol.equals("tcp")) {
        Logger.info(this, "***\t Setting up TCP initial hosts: "+cacheTCPInitialHosts);
        System.setProperty("jgroups.tcpping.initial_hosts",  cacheTCPInitialHosts);
      } else if (cacheProtocol.equals("udp")) {
        Logger.info(this, "***\t Setting up UDP address and port: "+mCastAddr+":"+mCastPort);
        System.setProperty("jgroups.udp.mcast_port", mCastPort);
        System.setProperty("jgroups.udp.mcast_addr", mCastAddr);
      } else {
        Logger.info(this, "Not Setting up any Properties as no protocal was found");
      }

      Logger.info(this, "***\t Prefer IPv4: "+(preferIPv4.equals("true") ? "enabled" : "disabled"));
      System.setProperty("java.net.preferIPv4Stack", preferIPv4);
     
     
      Logger.info(this, "***\t Setting up JChannel");

      if(channel!=null) {
          channel.disconnect();
      }
     
      channel = new JChannel(classLoader.getResource(cacheFile));
      channel.setReceiver(this);
     
      channel.connect(Config.getStringProperty("CACHE_JGROUPS_GROUP_NAME","dotCMSCluster"));
      channel.setOpt(JChannel.LOCAL, false);
      useJgroups = true;
      channel.send(new Message(null, null, TEST_MESSAGE));
      Address channelAddress = channel.getAddress();
      PhysicalAddress physicalAddr = (PhysicalAddress)channel.downcall(new Event(Event.GET_PHYSICAL_ADDRESS, channelAddress));
      String[] addrParts = physicalAddr.toString().split(":");
      String usedPort = addrParts[addrParts.length-1];

      localServer.setCachePort(Integer.parseInt(usedPort));
      serverAPI.updateServer(localServer);

      Logger.info(this, "***\t " + channel.toString(true));
      Logger.info(this, "***\t Ending JGroups Cluster Setup");

  }
View Full Code Here

Examples of com.dotcms.cluster.business.ServerAPI

    }
  }

  public void setClusterNode(Map<String, String> properties) throws Exception {
      String httpPort=null, transportTCPPort, bindAddr, initData;
      ServerAPI serverAPI = APILocator.getServerAPI();
      Server currentServer=null;
     
        if(Config.getBooleanProperty("CLUSTER_AUTOWIRE",true)) {

      String serverId = ConfigUtils.getServerId();
      //This line is added because when someone add a license the node is already up and working and reset the existing port
      shutDownNode();
      currentServer = serverAPI.getServer(serverId);

      String storedBindAddr = (UtilMethods.isSet(currentServer.getHost()) && !currentServer.getHost().equals("localhost"))
          ?currentServer.getHost():currentServer.getIpAddress();

      bindAddr = properties!=null && UtilMethods.isSet(properties.get("BIND_ADDRESS")) ? properties.get("BIND_ADDRESS")
          :Config.getStringProperty("es.network.host", storedBindAddr);

      currentServer.setHost(Config.getStringProperty("es.network.host", null));

      if(properties!=null && UtilMethods.isSet(properties.get("ES_TRANSPORT_TCP_PORT"))){
        transportTCPPort = getNextAvailableESPort(serverId,bindAddr,properties.get("ES_TRANSPORT_TCP_PORT"));
      } else if(UtilMethods.isSet(currentServer.getEsTransportTcpPort())){
        transportTCPPort = getNextAvailableESPort(serverId,bindAddr,currentServer.getEsTransportTcpPort().toString());
      }else{
        transportTCPPort = getNextAvailableESPort(serverId, bindAddr, null);
      }

      if(Config.getBooleanProperty("es.http.enabled", false)) {
        httpPort = properties!=null &&   UtilMethods.isSet(properties.get("ES_HTTP_PORT")) ? properties.get("ES_HTTP_PORT")
            :UtilMethods.isSet(currentServer.getEsHttpPort()) ? currentServer.getEsHttpPort().toString()
            :ClusterFactory.getNextAvailablePort(serverId, ServerPort.ES_HTTP_PORT);

        currentServer.setEsHttpPort(Integer.parseInt(httpPort));
      }     

      List<String> myself = new ArrayList<String>();
      myself.add(currentServer.getServerId());

      List<Server> aliveServers = serverAPI.getAliveServers(myself);

      currentServer.setEsTransportTcpPort(Integer.parseInt(transportTCPPort));

      aliveServers.add(currentServer);

      StringBuilder initialHosts = new StringBuilder();

      int i=0;
      for (Server server : aliveServers) {
        if(i>0) {
          initialHosts.append(",");
        }

        if(UtilMethods.isSet(server.getHost()) && !server.getHost().equals("localhost")) {
          initialHosts.append(server.getHost()).append(":").append(server.getEsTransportTcpPort());
        } else {
          initialHosts.append(server.getIpAddress()).append(":").append(server.getEsTransportTcpPort());
        }

        i++;
      }

      if(initialHosts.length()==0) {
        if(bindAddr.equals("localhost")) {
          initialHosts.append(currentServer.getIpAddress()).append(":").append(transportTCPPort);
        } else {
          initialHosts.append(bindAddr).append(":").append(transportTCPPort);
        }
      }

      initData=initialHosts.toString();
     
      try {
                serverAPI.updateServer(currentServer);
            } catch (DotDataException e) {
                Logger.error(this, "Error trying to update server. Server Id: " + currentServer.getServerId());
            }
        }
        else {
View Full Code Here

Examples of com.dotcms.cluster.business.ServerAPI

    public Response getNodesInfo ( @Context HttpServletRequest request, @PathParam ("params") String params ) throws DotStateException, DotDataException, DotSecurityException, JSONException {

        InitDataObject initData = init( params, true, request, false, "9");
        ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );
       
        ServerAPI serverAPI = APILocator.getServerAPI();
        List<Server> servers = serverAPI.getAllServers();
        String myServerId = serverAPI.readServerId();

        List<ServerActionBean> actionBeans = new ArrayList<ServerActionBean>();
        List<ServerActionBean> resultActionBeans = new ArrayList<ServerActionBean>();
        JSONArray jsonNodes = new JSONArray();
       
View Full Code Here

Examples of com.dotcms.cluster.business.ServerAPI

        InitDataObject initData = init( params, true, request, false, "9" );
        ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );

        JSONObject jsonNode = new JSONObject();
        ServerAPI serverAPI = APILocator.getServerAPI();

        String serverId = serverAPI.readServerId();
        Server server = serverAPI.getServer(serverId);
        String cachePort = ClusterFactory.getNextAvailablePort(serverId, ServerPort.CACHE_PORT);
        String esPort = ClusterFactory.getNextAvailablePort(serverId, ServerPort.ES_TRANSPORT_TCP_PORT);

        jsonNode.put("BIND_ADDRESS", server!=null&&UtilMethods.isSet(server.getIpAddress())?server.getIpAddress():"");
        jsonNode.put("CACHE_BINDPORT", server!=null&&UtilMethods.isSet(server.getCachePort())?server.getCachePort():cachePort);
View Full Code Here

Examples of org.jclouds.glesys.features.ServerApi

      }, 30, 1, SECONDS);
      assertTrue(result.apply(before + 1));
   }

   protected Predicate<State> createServer(String hostName) {
      final ServerApi serverApi = api.getServerApi();

      ServerDetails testServer = serverApi.createWithHostnameAndRootPassword(
            ServerSpec.builder().datacenter("Falkenberg").platform("OpenVZ").templateName("Ubuntu 10.04 LTS 32-bit")
                  .diskSizeGB(5).memorySizeMB(512).cpuCores(1).transferGB(50).build(), hostName, UUID.randomUUID()
                  .toString().replace("-",""));

      assertNotNull(testServer.getId());
View Full Code Here

Examples of org.jclouds.glesys.features.ServerApi

      }, 30, 1, SECONDS);
      assertTrue(result.apply(before + 1));
   }

   protected Predicate<State> createServer(String hostName) {
      final ServerApi serverApi = api.getServerApi();

      ServerDetails testServer = serverApi.createWithHostnameAndRootPassword(
            ServerSpec.builder().datacenter("Falkenberg").platform("OpenVZ").templateName("Ubuntu 10.04 LTS 32-bit")
                  .diskSizeGB(5).memorySizeMB(512).cpuCores(1).transferGB(50).build(), hostName, UUID.randomUUID()
                  .toString().replace("-",""));

      assertNotNull(testServer.getId());
View Full Code Here

Examples of org.jclouds.glesys.features.ServerApi

      }, 30, 1, SECONDS);
      assertTrue(result.apply(before + 1));
   }

   protected Predicate<State> createServer(String hostName) {
      final ServerApi serverApi = api.getServerApi();

      ServerDetails testServer = serverApi.createWithHostnameAndRootPassword(
            ServerSpec.builder().datacenter("Falkenberg").platform("OpenVZ").templateName("Ubuntu 10.04 LTS 32-bit")
                  .diskSizeGB(5).memorySizeMB(512).cpuCores(1).transferGB(50).build(), hostName, UUID.randomUUID()
                  .toString().replace("-", ""));

      assertNotNull(testServer.getId());
View Full Code Here

Examples of org.jclouds.openstack.nova.v2_0.features.ServerApi

   @Override
   public void setup() {
      super.setup();
      zones = api.getConfiguredZones();
      for (String zone : zones){
         ServerApi serverApi = api.getServerApiForZone(zone);
         for (Resource server : serverApi.list().concat()){
            if (server.getName().equals(hostName))
               serverApi.delete(server.getId());
         }
      }
   }
View Full Code Here

Examples of org.jclouds.openstack.nova.v2_0.features.ServerApi

      setIfTestSystemPropertyPresent(props, NovaProperties.AUTO_ALLOCATE_FLOATING_IPS);
      return props;
   }
  
   protected Server createServerInZone(String zoneId) {
      ServerApi serverApi = api.getServerApiForZone(zoneId);
      ServerCreated server = serverApi.create(hostName, imageIdForZone(zoneId), flavorRefForZone(zoneId));
      blockUntilServerInState(server.getId(), serverApi, Status.ACTIVE);
      return serverApi.get(server.getId());
   }
View Full Code Here

Examples of org.jclouds.openstack.nova.v2_0.features.ServerApi

         this.api = checkNotNull(api, "api");
      }

      @Override
      protected Function<Object, IterableWithMarker<Resource>> markerToNextForCallingArg0(final String zone) {
         final ServerApi serverApi = api.getServerApiForZone(zone);
         return new Function<Object, IterableWithMarker<Resource>>() {

            @SuppressWarnings("unchecked")
            @Override
            public IterableWithMarker<Resource> apply(Object input) {
               return IterableWithMarker.class.cast(serverApi.list(marker(input.toString())));
            }

            @Override
            public String toString() {
               return "list()";
View Full Code Here
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.