コード例 #1
0
  private static void _registerClusterOrder(
      HttpServletRequest request,
      ClusterNode clusterNode,
      String orderUuid,
      String productEntryName,
      int maxServers)
      throws Exception {

    MethodHandler methodHandler =
        new MethodHandler(_registerOrderMethodKey, orderUuid, productEntryName, maxServers);

    ClusterRequest clusterRequest =
        ClusterRequest.createUnicastRequest(methodHandler, clusterNode.getClusterNodeId());

    FutureClusterResponses futureClusterResponses = ClusterExecutorUtil.execute(clusterRequest);

    ClusterNodeResponses clusterNodeResponses =
        futureClusterResponses.get(20000, TimeUnit.MILLISECONDS);

    ClusterNodeResponse clusterNodeResponse = clusterNodeResponses.getClusterResponse(clusterNode);

    Map<String, Object> attributes = (Map<String, Object>) clusterNodeResponse.getResult();

    for (Map.Entry<String, Object> entry : attributes.entrySet()) {
      request.setAttribute(
          clusterNode.getClusterNodeId() + StringPool.UNDERLINE + entry.getKey(), entry.getValue());
    }
  }
コード例 #2
0
  private void _loadIndexFromCluster(IndexAccessor indexAccessor, long localLastGeneration) {

    List<Address> clusterNodeAddresses = ClusterExecutorUtil.getClusterNodeAddresses();

    int clusterNodeAddressesCount = clusterNodeAddresses.size();

    if (clusterNodeAddressesCount <= 1) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Do not load indexes because there is either one portal "
                + "instance or no portal instances in the cluster");
      }

      return;
    }

    ClusterRequest clusterRequest =
        ClusterRequest.createMulticastRequest(
            new MethodHandler(_getLastGenerationMethodKey, indexAccessor.getCompanyId()), true);

    ClusterExecutorUtil.execute(
        clusterRequest,
        new LoadIndexClusterResponseCallback(
            indexAccessor, clusterNodeAddressesCount, localLastGeneration));
  }
コード例 #3
0
  private ObjectValuePair<String, URL> _getBootupClusterNodeObjectValuePair(Address bootupAddress) {

    ClusterRequest clusterRequest =
        ClusterRequest.createUnicastRequest(
            new MethodHandler(_createTokenMethodKey, _CLUSTER_LINK_NODE_BOOTUP_RESPONSE_TIMEOUT),
            bootupAddress);

    FutureClusterResponses futureClusterResponses = ClusterExecutorUtil.execute(clusterRequest);

    BlockingQueue<ClusterNodeResponse> clusterNodeResponses =
        futureClusterResponses.getPartialResults();

    try {
      ClusterNodeResponse clusterNodeResponse =
          clusterNodeResponses.poll(
              _CLUSTER_LINK_NODE_BOOTUP_RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS);

      ClusterNode clusterNode = clusterNodeResponse.getClusterNode();

      InetSocketAddress inetSocketAddress = clusterNode.getPortalInetSocketAddress();

      if (inetSocketAddress == null) {
        StringBundler sb = new StringBundler(6);

        sb.append("Invalid cluster node InetSocketAddress ");
        sb.append(". The InetSocketAddress is set by the first ");
        sb.append("request or configured in portal.properties by the");
        sb.append("properties ");
        sb.append("\"portal.instance.http.inet.socket.address\" and ");
        sb.append("\"portal.instance.https.inet.socket.address\".");

        throw new Exception(sb.toString());
      }

      InetAddress inetAddress = inetSocketAddress.getAddress();

      String fileName = PortalUtil.getPathContext();

      if (!fileName.endsWith(StringPool.SLASH)) {
        fileName = fileName.concat(StringPool.SLASH);
      }

      fileName = fileName.concat("lucene/dump");

      URL url =
          new URL(_protocol, inetAddress.getHostAddress(), inetSocketAddress.getPort(), fileName);

      String transientToken = (String) clusterNodeResponse.getResult();

      return new ObjectValuePair<String, URL>(transientToken, url);
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  private FutureClusterResponses doAction() throws ManageActionException, SystemException {

    MethodHandler manageActionMethodHandler =
        PortalManagerUtil.createManageActionMethodHandler(_manageAction);

    ClusterRequest clusterRequest = null;

    if (_clusterGroup.isWholeCluster()) {
      clusterRequest = ClusterRequest.createMulticastRequest(manageActionMethodHandler);
    } else {
      verifyClusterGroup();

      clusterRequest =
          ClusterRequest.createUnicastRequest(
              manageActionMethodHandler, _clusterGroup.getClusterNodeIdsArray());
    }

    return ClusterExecutorUtil.execute(clusterRequest);
  }
コード例 #5
0
  public static Map<String, String> getClusterServerInfo(String clusterNodeId) throws Exception {

    List<ClusterNode> clusterNodes = ClusterExecutorUtil.getClusterNodes();

    ClusterNode clusterNode = null;

    for (ClusterNode curClusterNode : clusterNodes) {
      String curClusterNodeId = curClusterNode.getClusterNodeId();

      if (curClusterNodeId.equals(clusterNodeId)) {
        clusterNode = curClusterNode;

        break;
      }
    }

    if (clusterNode == null) {
      return null;
    }

    try {
      if (clusterNode.equals(ClusterExecutorUtil.getLocalClusterNode())) {
        return getServerInfo();
      }

      ClusterRequest clusterRequest =
          ClusterRequest.createUnicastRequest(_getServerInfoMethodHandler, clusterNodeId);

      FutureClusterResponses futureClusterResponses = ClusterExecutorUtil.execute(clusterRequest);

      ClusterNodeResponses clusterNodeResponses =
          futureClusterResponses.get(20000, TimeUnit.MILLISECONDS);

      ClusterNodeResponse clusterNodeResponse =
          clusterNodeResponses.getClusterResponse(clusterNode);

      return (Map<String, String>) clusterNodeResponse.getResult();
    } catch (Exception e) {
      _log.error(e, e);

      throw e;
    }
  }
コード例 #6
0
  protected String importTheme(LayoutSet layoutSet, InputStream themeZip) throws Exception {

    ThemeLoader themeLoader = ThemeLoaderFactory.getDefaultThemeLoader();

    if (themeLoader == null) {
      _log.error("No theme loaders are deployed");

      return null;
    }

    ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(themeZip);

    String lookAndFeelXML = zipReader.getEntryAsString("liferay-look-and-feel.xml");

    String themeId = String.valueOf(layoutSet.getGroupId());

    if (layoutSet.isPrivateLayout()) {
      themeId += "-private";
    } else {
      themeId += "-public";
    }

    if (PropsValues.THEME_LOADER_NEW_THEME_ID_ON_IMPORT) {
      Date now = new Date();

      themeId += "-" + Time.getShortTimestamp(now);
    }

    String themeName = themeId;

    lookAndFeelXML =
        StringUtil.replace(
            lookAndFeelXML,
            new String[] {"[$GROUP_ID$]", "[$THEME_ID$]", "[$THEME_NAME$]"},
            new String[] {String.valueOf(layoutSet.getGroupId()), themeId, themeName});

    FileUtil.deltree(themeLoader.getFileStorage() + StringPool.SLASH + themeId);

    List<String> zipEntries = zipReader.getEntries();

    for (String zipEntry : zipEntries) {
      String key = zipEntry;

      if (key.equals("liferay-look-and-feel.xml")) {
        FileUtil.write(
            themeLoader.getFileStorage() + StringPool.SLASH + themeId + StringPool.SLASH + key,
            lookAndFeelXML.getBytes());
      } else {
        InputStream is = zipReader.getEntryAsInputStream(zipEntry);

        FileUtil.write(
            themeLoader.getFileStorage() + StringPool.SLASH + themeId + StringPool.SLASH + key, is);
      }
    }

    themeLoader.loadThemes();

    ClusterRequest clusterRequest =
        ClusterRequest.createMulticastRequest(_loadThemesMethodHandler, true);

    clusterRequest.setFireAndForget(true);

    ClusterExecutorUtil.execute(clusterRequest);

    themeId += PortletConstants.WAR_SEPARATOR + themeLoader.getServletContextName();

    return PortalUtil.getJsSafePortletId(themeId);
  }
コード例 #7
0
    public void run() {
      _countDownLatch.countDown();

      String logPrefix = StringPool.BLANK;

      if (_log.isInfoEnabled()) {
        Thread currentThread = Thread.currentThread();

        if (_master) {
          logPrefix =
              "Monitor thread name "
                  + currentThread.getName()
                  + " with thread ID "
                  + currentThread.getId();
        } else {
          logPrefix =
              "Thread name " + currentThread.getName() + " with thread ID " + currentThread.getId();
        }
      }

      if (!_master && _log.isInfoEnabled()) {
        _log.info(logPrefix + " synchronized on latch. Waiting for others.");
      }

      try {
        if (_master) {
          _countDownLatch.await();
        } else {
          boolean result =
              _countDownLatch.await(
                  PropsValues.LUCENE_CLUSTER_INDEX_LOADING_SYNC_TIMEOUT, TimeUnit.MILLISECONDS);

          if (!result) {
            _log.error(
                logPrefix + " timed out. You may need to " + "re-trigger a reindex process.");
          }
        }
      } catch (InterruptedException ie) {
        if (_master) {
          _log.error(
              logPrefix + " was interrupted. Skip cluster index " + "loading notification.", ie);

          return;
        } else {
          _log.error(
              logPrefix + " was interrupted. You may need to " + "re-trigger a reindex process.",
              ie);
        }
      }

      if (_master) {
        Address localClusterNodeAddress = ClusterExecutorUtil.getLocalClusterNodeAddress();

        ClusterRequest clusterRequest =
            ClusterRequest.createMulticastRequest(
                new MethodHandler(
                    _loadIndexesFromClusterMethodKey, _companyIds, localClusterNodeAddress),
                true);

        try {
          ClusterExecutorUtil.execute(clusterRequest);
        } catch (SystemException se) {
          _log.error("Unable to notify peers to start index loading", se);
        }

        if (_log.isInfoEnabled()) {
          _log.info(logPrefix + " unlocked latch. Notified peers to " + "start index loading.");
        }
      }
    }