예제 #1
0
  private static void checkForInvalidAttributes(String cacheName, CacheEntityV2 resource)
      throws ServiceExecutionException {
    boolean invalidAttributesFound = false;
    StringBuilder errorMessage =
        new StringBuilder("You are not allowed to update those attributes : ");
    if (resource.getName() != null && !resource.getName().equals(cacheName)) {
      errorMessage.append("name ");
      invalidAttributesFound = true;
    }
    Set<String> validAttributes = new HashSet<String>();
    validAttributes.add(SamplerRepoEntry.ENABLED_ATTR);
    validAttributes.add(SamplerRepoEntry.BULK_LOAD_ENABLED);
    validAttributes.add(SamplerRepoEntry.MAX_ELEMENTS_ON_DISK);
    validAttributes.add(SamplerRepoEntry.LOGGING_ENABLED);
    validAttributes.add(SamplerRepoEntry.MAX_BYTES_LOCAL_DISK_STRING);
    validAttributes.add(SamplerRepoEntry.MAX_BYTES_LOCAL_HEAP_STRING);
    validAttributes.add(SamplerRepoEntry.MAX_ENTRIES_LOCAL_HEAP);
    validAttributes.add(SamplerRepoEntry.MAX_ENTRIES_IN_CACHE);
    validAttributes.add(SamplerRepoEntry.TIME_TO_IDLE_SEC);
    validAttributes.add(SamplerRepoEntry.TIME_TO_LIVE_SEC);

    for (Map.Entry<String, Object> attribute : resource.getAttributes().entrySet()) {
      String key = attribute.getKey();
      if (!validAttributes.contains(key)) {
        errorMessage.append(key).append(" ");
        invalidAttributesFound = true;
      }
    }
    if (invalidAttributesFound) {
      errorMessage.append(". Only ");
      for (String validAttribute : validAttributes) {
        errorMessage.append(validAttribute).append(" ");
      }
      errorMessage.append("can be updated for a Cache.");
      throw new ServiceExecutionException(errorMessage.toString());
    }
  }
예제 #2
0
    public void updateCache(String cacheSamplerName, CacheEntityV2 cacheResource)
        throws ServiceExecutionException {
      cacheSamplerMapLock.writeLock().lock();

      CacheSampler cs;
      try {
        cs = cacheSamplersByName.get(cacheSamplerName);

        if (cs != null) {
          try {

            checkForInvalidAttributes(cacheSamplerName, cacheResource);

            Boolean enabledAttr = (Boolean) cacheResource.getAttributes().get(ENABLED_ATTR);
            if (enabledAttr != null) {
              cs.setEnabled(enabledAttr);
            }

            Boolean enabledBlkLoad = (Boolean) cacheResource.getAttributes().get(BULK_LOAD_ENABLED);
            if (enabledBlkLoad != null) {
              cs.setNodeBulkLoadEnabled(enabledBlkLoad);
            }

            Integer maxElementsOnDiskAttr =
                (Integer) cacheResource.getAttributes().get(MAX_ELEMENTS_ON_DISK);
            if (maxElementsOnDiskAttr != null) {
              cs.setMaxElementsOnDisk(maxElementsOnDiskAttr);
            }

            Boolean loggingEnabledAttr =
                (Boolean) cacheResource.getAttributes().get(LOGGING_ENABLED);
            if (loggingEnabledAttr != null) {
              cs.setLoggingEnabled(loggingEnabledAttr);
            }

            Object mbldsAttr = cacheResource.getAttributes().get(MAX_BYTES_LOCAL_DISK_STRING);
            if (mbldsAttr != null) {
              cs.setMaxBytesLocalDiskAsString(mbldsAttr.toString());
            }

            Object mblhsAttr = cacheResource.getAttributes().get(MAX_BYTES_LOCAL_HEAP_STRING);
            if (mblhsAttr != null) {
              cs.setMaxBytesLocalHeapAsString(mblhsAttr.toString());
            }

            Integer melhAttr = (Integer) cacheResource.getAttributes().get(MAX_ENTRIES_LOCAL_HEAP);
            if (melhAttr != null) {
              cs.setMaxEntriesLocalHeap(melhAttr);
            }

            Integer meicAttr = (Integer) cacheResource.getAttributes().get(MAX_ENTRIES_IN_CACHE);
            if (meicAttr != null) {
              cs.setMaxEntriesInCache(meicAttr);
            }

            Object ttiAttr = cacheResource.getAttributes().get(TIME_TO_IDLE_SEC);
            if (ttiAttr != null) {
              cs.setTimeToIdleSeconds(Long.parseLong(ttiAttr.toString()));
            }

            Object ttlAttr = cacheResource.getAttributes().get(TIME_TO_LIVE_SEC);
            if (ttlAttr != null) {
              cs.setTimeToLiveSeconds(Long.parseLong(ttlAttr.toString()));
            }
          } catch (RuntimeException e) {
            throw new ServiceExecutionException(e);
          }

        } else {
          throw new ServiceExecutionException("Cache not found !");
        }

      } finally {
        cacheSamplerMapLock.writeLock().unlock();
      }
    }