Example #1
0
  public static void main(String[] args) throws Exception {
    CommandLineOptionHelper helper = new CommandLineOptionHelper(args);
    GridRole role = GridRole.find(args);

    if (role == null) {
      printInfoAboutRoles(helper);
      return;
    }

    if (helper.isParamPresent("-help") || helper.isParamPresent("-h")) {
      if (launchers.containsKey(role)) {
        launchers.get(role).printUsage();
      } else {
        printInfoAboutRoles(helper);
      }
      return;
    }

    configureLogging(helper);

    if (launchers.containsKey(role)) {
      try {
        launchers.get(role).launch(args, log);
      } catch (Exception e) {
        launchers.get(role).printUsage();
        e.printStackTrace();
      }
    } else {
      throw new GridConfigurationException("Unknown role: " + role);
    }
  }
Example #2
0
  /** Implements {@link Files#readAttributes(Path, String, LinkOption...)}. */
  public ImmutableMap<String, Object> readAttributes(File file, String attributes) {
    String view = getViewName(attributes);
    List<String> attrs = getAttributeNames(attributes);

    if (attrs.size() > 1 && attrs.contains(ALL_ATTRIBUTES)) {
      // attrs contains * and other attributes
      throw new IllegalArgumentException("invalid attributes: " + attributes);
    }

    Map<String, Object> result = new HashMap<>();
    if (attrs.size() == 1 && attrs.contains(ALL_ATTRIBUTES)) {
      // for 'view:*' format, get all keys for all providers for the view
      AttributeProvider provider = providersByName.get(view);
      readAll(file, provider, result);

      for (String inheritedView : provider.inherits()) {
        AttributeProvider inheritedProvider = providersByName.get(inheritedView);
        readAll(file, inheritedProvider, result);
      }
    } else {
      // for 'view:attr1,attr2,etc'
      for (String attr : attrs) {
        result.put(attr, getAttribute(file, view, attr));
      }
    }

    return ImmutableMap.copyOf(result);
  }
Example #3
0
 public SmartNameFieldMappers smartName(String smartName, @Nullable String[] types) {
   if (types == null || types.length == 0) {
     return smartName(smartName);
   }
   for (String type : types) {
     DocumentMapper documentMapper = mappers.get(type);
     // we found a mapper
     if (documentMapper != null) {
       // see if we find a field for it
       FieldMappers mappers = documentMapper.mappers().smartName(smartName);
       if (mappers != null) {
         return new SmartNameFieldMappers(this, mappers, documentMapper, false);
       }
     }
   }
   // did not find explicit field in the type provided, see if its prefixed with type
   int dotIndex = smartName.indexOf('.');
   if (dotIndex != -1) {
     String possibleType = smartName.substring(0, dotIndex);
     DocumentMapper possibleDocMapper = mappers.get(possibleType);
     if (possibleDocMapper != null) {
       String possibleName = smartName.substring(dotIndex + 1);
       FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
       if (mappers != null) {
         return new SmartNameFieldMappers(this, mappers, possibleDocMapper, true);
       }
     }
   }
   // we did not find the field mapping in any of the types, so don't go and try to find
   // it in other types...
   return null;
 }
 @Test(dependsOnMethods = "testGetLocation")
 public void testAddPublicKey() throws Exception {
   try {
     connection.addPublicKey(TAG, keyPair.get("public"));
     key = connection.getKey(TAG);
     try {
       assert key.getInstanceIds().equals(ImmutableSet.<String>of()) : key;
     } catch (AssertionError e) {
       // inconsistency in the key api when recreating a key
       // http://www-180.ibm.com/cloud/enterprise/beta/ram/community/discussionTopic.faces?guid={DA689AEE-783C-6FE7-6F9F-DFEE9763F806}&v=1&fid=1068&tid=1528
     }
   } catch (IllegalStateException e) {
     // must have been found
     connection.updatePublicKey(TAG, keyPair.get("public"));
     key = connection.getKey(TAG);
     for (String instanceId : key.getInstanceIds()) {
       Instance instance = connection.getInstance(instanceId);
       if (instance.getStatus() == Instance.Status.FAILED
           || instance.getStatus() == Instance.Status.ACTIVE) {
         killInstance(instance.getId());
       }
     }
   }
   assertEquals(key.getName(), TAG);
   assert keyPair.get("public").indexOf(key.getKeyMaterial()) > 0;
   assertNotNull(key.getLastModifiedTime());
 }
Example #5
0
 public SmartNameObjectMapper smartNameObjectMapper(String smartName, @Nullable String[] types) {
   if (types == null || types.length == 0) {
     return smartNameObjectMapper(smartName);
   }
   for (String type : types) {
     DocumentMapper possibleDocMapper = mappers.get(type);
     if (possibleDocMapper != null) {
       ObjectMapper mapper = possibleDocMapper.objectMappers().get(smartName);
       if (mapper != null) {
         return new SmartNameObjectMapper(mapper, possibleDocMapper);
       }
     }
   }
   // did not find one, see if its prefixed by type
   int dotIndex = smartName.indexOf('.');
   if (dotIndex != -1) {
     String possibleType = smartName.substring(0, dotIndex);
     DocumentMapper possibleDocMapper = mappers.get(possibleType);
     if (possibleDocMapper != null) {
       String possiblePath = smartName.substring(dotIndex + 1);
       ObjectMapper mapper = possibleDocMapper.objectMappers().get(possiblePath);
       if (mapper != null) {
         return new SmartNameObjectMapper(mapper, possibleDocMapper);
       }
     }
   }
   // did not explicitly find one under the types provided, or prefixed by type...
   return null;
 }
Example #6
0
  private void removeObjectFieldMappers(DocumentMapper docMapper) {
    // we need to remove those mappers
    for (FieldMapper mapper : docMapper.mappers()) {
      FieldMappers mappers = nameFieldMappers.get(mapper.names().name());
      if (mappers != null) {
        mappers = mappers.remove(mapper);
        if (mappers.isEmpty()) {
          nameFieldMappers =
              newMapBuilder(nameFieldMappers).remove(mapper.names().name()).immutableMap();
        } else {
          nameFieldMappers =
              newMapBuilder(nameFieldMappers).put(mapper.names().name(), mappers).immutableMap();
        }
      }

      mappers = indexNameFieldMappers.get(mapper.names().indexName());
      if (mappers != null) {
        mappers = mappers.remove(mapper);
        if (mappers.isEmpty()) {
          indexNameFieldMappers =
              newMapBuilder(indexNameFieldMappers)
                  .remove(mapper.names().indexName())
                  .immutableMap();
        } else {
          indexNameFieldMappers =
              newMapBuilder(indexNameFieldMappers)
                  .put(mapper.names().indexName(), mappers)
                  .immutableMap();
        }
      }

      mappers = fullNameFieldMappers.get(mapper.names().fullName());
      if (mappers != null) {
        mappers = mappers.remove(mapper);
        if (mappers.isEmpty()) {
          fullNameFieldMappers =
              newMapBuilder(fullNameFieldMappers).remove(mapper.names().fullName()).immutableMap();
        } else {
          fullNameFieldMappers =
              newMapBuilder(fullNameFieldMappers)
                  .put(mapper.names().fullName(), mappers)
                  .immutableMap();
        }
      }
    }

    for (ObjectMapper mapper : docMapper.objectMappers().values()) {
      ObjectMappers mappers = objectMappers.get(mapper.fullPath());
      if (mappers != null) {
        mappers = mappers.remove(mapper);
        if (mappers.isEmpty()) {
          objectMappers = newMapBuilder(objectMappers).remove(mapper.fullPath()).immutableMap();
        } else {
          objectMappers =
              newMapBuilder(objectMappers).put(mapper.fullPath(), mappers).immutableMap();
        }
      }
    }
  }
 /**
  * Sometimes, the default mapping exists and an actual mapping is not created yet (introduced), in
  * this case, we want to return the default mapping in case it has some default mapping
  * definitions.
  *
  * <p>Note, once the mapping type is introduced, the default mapping is applied on the actual
  * typed MappingMetaData, setting its routing, timestamp, and so on if needed.
  */
 @Nullable
 public MappingMetaData mappingOrDefault(String mappingType) {
   MappingMetaData mapping = mappings.get(mappingType);
   if (mapping != null) {
     return mapping;
   }
   return mappings.get(MapperService.DEFAULT_MAPPING);
 }
 @Override
 public String get(String setting) {
   String retVal = settings.get(setting);
   if (retVal != null) {
     return retVal;
   }
   // try camel case version
   return settings.get(toCamelCase(setting));
 }
 public AdsAmazonObject clickAmazonArticleLink(String linkName) {
   waitForAmazonResponse();
   WebElement amazonArticleLink =
       driver.findElement(By.cssSelector(amazonLinkCssSelectors.get(linkName)));
   waitForElementByElement(amazonArticleLink);
   amazonArticleLink.click();
   waitTitleChangesTo(amazonLinkTitles.get(linkName));
   return this;
 }
    private static Builder createDefault() {
      Builder builder = new Builder();

      builder
          .getGroupSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .updateGroupSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default"));

      return builder;
    }
  @Test(
      dependsOnMethods = {
        "testAddPublicKey",
        "testAllocateIpAddress",
        "testCreateVolume",
        "resolveImageAndInstanceType"
      })
  public void testCreateInstanceWithIpAndVolume() throws Exception {
    String name = TAG + "1";
    killInstance(name);

    instance2 =
        connection.createInstanceInLocation(
            location.getId(),
            name,
            image.getId(),
            instanceType.getId(),
            attachIp(ip.getId())
                .authorizePublicKey(key.getName())
                .mountVolume(volume.getId(), "/mnt"));

    assertBeginState(instance2, name);
    assertIpHostAndStatusNEW(instance2);
    blockUntilRunning(instance2);
    instance2 = assertRunning(instance2, name);

    volume = connection.getVolume(volume.getId());
    assertEquals(volume.getInstanceId(), instance2.getId());

    refreshIpAndReturnAllAddresses();
    assertEquals(ip.getInstanceId(), instance2.getId());
    assertEquals(ip.getIp(), instance2.getIp());
    sshAndDf(
        new IPSocket(instance2.getIp(), 22), new Credentials("idcuser", keyPair.get("private")));
  }
Example #12
0
 private void serializeNullValue(ParseContext context, String lastFieldName) throws IOException {
   // we can only handle null values if we have mappings for them
   Mapper mapper = mappers.get(lastFieldName);
   if (mapper != null) {
     mapper.parse(context);
   }
 }
Example #13
0
 private void serializeArray(ParseContext context, String lastFieldName) throws IOException {
   String arrayFieldName = lastFieldName;
   Mapper mapper = mappers.get(lastFieldName);
   if (mapper != null && mapper instanceof ArrayValueMapperParser) {
     mapper.parse(context);
   } else {
     XContentParser parser = context.parser();
     XContentParser.Token token;
     while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
       if (token == XContentParser.Token.START_OBJECT) {
         serializeObject(context, lastFieldName);
       } else if (token == XContentParser.Token.START_ARRAY) {
         serializeArray(context, lastFieldName);
       } else if (token == XContentParser.Token.FIELD_NAME) {
         lastFieldName = parser.currentName();
       } else if (token == XContentParser.Token.VALUE_NULL) {
         serializeNullValue(context, lastFieldName);
       } else if (token == null) {
         throw new MapperParsingException(
             "object mapping for ["
                 + name
                 + "] with array for ["
                 + arrayFieldName
                 + "] tried to parse as array, but got EOF, is there a mismatch in types for the same field?");
       } else {
         serializeValue(context, lastFieldName, token);
       }
     }
   }
 }
Example #14
0
    @Override
    public Query visitFunction(Function function, Context context) {
      assert function != null;
      if (fieldIgnored(function, context)) {
        return Queries.newMatchAllQuery();
      }
      function = rewriteAndValidateFields(function, context);

      FunctionToQuery toQuery = functions.get(function.info().ident().name());
      if (toQuery == null) {
        return genericFunctionQuery(function, context);
      }

      Query query;
      try {
        query = toQuery.apply(function, context);
      } catch (IOException e) {
        throw ExceptionsHelper.convertToRuntime(e);
      } catch (UnsupportedOperationException e) {
        return genericFunctionQuery(function, context);
      }
      if (query == null) {
        query = queryFromInnerFunction(function, context);
        if (query == null) {
          return genericFunctionQuery(function, context);
        }
      }
      return query;
    }
 /**
  * Convert a TypeNode to a Java type declaration.
  *
  * <p>post order, recursive.
  */
 private static String generateTypeDeclaration(
     final TypeNode type, final IntermediateType parentType) {
   if (!type.isContainer()) {
     if (parentType == IntermediateType.ARRAY) {
       return TypeMap.JAVA_TYPE_MAP.get(type.getValue());
     } else {
       return JAVA_CLASS_MAP.get(type.getValue());
     }
   }
   if (type.getValue() == IntermediateType.ARRAY) {
     return generateTypeDeclaration(type.getElementType().get(), type.getValue()) + "[]";
   } else {
     final String containerTypeStr = TypeMap.JAVA_TYPE_MAP.get(type.getValue());
     if (type.getKeyType().isPresent()) {
       return containerTypeStr
           + "<"
           + generateTypeDeclaration(type.getKeyType().get(), type.getValue())
           + ","
           + generateTypeDeclaration(type.getElementType().get(), type.getValue())
           + ">";
     } else {
       return containerTypeStr
           + "<"
           + generateTypeDeclaration(type.getElementType().get(), type.getValue())
           + ">";
     }
   }
 }
Example #16
0
  @Test
  public void shouldBePossibleToCreateStateMap() {
    ImmutableMap<String, AddressState> map = addressMapBuilder().asStateMap();

    assertThat(map.get("a").city, equalTo("Uppsala"));
    assertThat(map.get("b").city, equalTo("Stockholm"));
  }
Example #17
0
 // never expose this to the outside world, we need to reparse the doc mapper so we get fresh
 // instances of field mappers to properly remove existing doc mapper
 private void add(DocumentMapper mapper) {
   synchronized (mutex) {
     if (mapper.type().charAt(0) == '_') {
       throw new InvalidTypeNameException(
           "mapping type name [" + mapper.type() + "] can't start with '_'");
     }
     if (mapper.type().contains("#")) {
       throw new InvalidTypeNameException(
           "mapping type name [" + mapper.type() + "] should not include '#' in it");
     }
     if (mapper.type().contains(",")) {
       throw new InvalidTypeNameException(
           "mapping type name [" + mapper.type() + "] should not include ',' in it");
     }
     if (mapper.type().contains(".")) {
       logger.warn(
           "Type [{}] contains a '.', it is recommended not to include it within a type name",
           mapper.type());
     }
     // we can add new field/object mappers while the old ones are there
     // since we get new instances of those, and when we remove, we remove
     // by instance equality
     DocumentMapper oldMapper = mappers.get(mapper.type());
     mapper.addFieldMapperListener(fieldMapperListener, true);
     mapper.addObjectMapperListener(objectMapperListener, true);
     mappers = newMapBuilder(mappers).put(mapper.type(), mapper).immutableMap();
     if (oldMapper != null) {
       removeObjectFieldMappers(oldMapper);
       oldMapper.close();
     }
   }
 }
Example #18
0
 /**
  * Returns smart field mappers based on a smart name. A smart name is one that can optioannly be
  * prefixed with a type (and then a '.'). If it is, then the {@link
  * MapperService.SmartNameFieldMappers} will have the doc mapper set.
  *
  * <p>
  *
  * <p>It also (without the optional type prefix) try and find the {@link FieldMappers} for the
  * specific name. It will first try to find it based on the full name (with the dots if its a
  * compound name). If it is not found, will try and find it based on the indexName (which can be
  * controlled in the mapping), and last, will try it based no the name itself.
  *
  * <p>
  *
  * <p>If nothing is found, returns null.
  */
 public SmartNameFieldMappers smartName(String smartName) {
   int dotIndex = smartName.indexOf('.');
   if (dotIndex != -1) {
     String possibleType = smartName.substring(0, dotIndex);
     DocumentMapper possibleDocMapper = mappers.get(possibleType);
     if (possibleDocMapper != null) {
       String possibleName = smartName.substring(dotIndex + 1);
       FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
       if (mappers != null) {
         return new SmartNameFieldMappers(this, mappers, possibleDocMapper, true);
       }
     }
   }
   FieldMappers fieldMappers = fullName(smartName);
   if (fieldMappers != null) {
     return new SmartNameFieldMappers(this, fieldMappers, null, false);
   }
   fieldMappers = indexName(smartName);
   if (fieldMappers != null) {
     return new SmartNameFieldMappers(this, fieldMappers, null, false);
   }
   fieldMappers = name(smartName);
   if (fieldMappers != null) {
     return new SmartNameFieldMappers(this, fieldMappers, null, false);
   }
   return null;
 }
    public Optional<Long> getArtifactSizeBytes() {
      if (eventInfo.containsKey(ARTIFACT_SIZE_BYTES_KEY)) {
        return Optional.of((long) eventInfo.get(ARTIFACT_SIZE_BYTES_KEY));
      }

      return Optional.absent();
    }
Example #20
0
 /** Opened an index input in raw form, no decompression for example. */
 public IndexInput openInputRaw(String name, IOContext context) throws IOException {
   StoreFileMetaData metaData = filesMetadata.get(name);
   if (metaData == null) {
     throw new FileNotFoundException(name);
   }
   return metaData.directory().openInput(name, context);
 }
 protected String getMsgStyle(FacesContext facesContext, UIComponent component, Object msg)
     throws IOException {
   MessageForRender message = (MessageForRender) msg;
   SeverityAttributes severityAttributes = SEVERITY_MAP.get(message.getSeverity());
   String style = buildSeverityAttribute(component, null, severityAttributes.styleAttribute, ';');
   return style;
 }
 private void showGuide() {
   final Integer guideResource = GUIDE_IMAGE_OF_LINE_TYPES.get(this.lineType);
   if (isLandscape()) {
     return;
   }
   getActivity()
       .runOnUiThread(
           new Runnable() {
             @Override
             public void run() {
               Log.d(TAG, "to set image resource");
               if (guideResource == null) {
                 maskLayer.setVisibility(View.GONE);
                 return;
               }
               if (getActivity() != null
                   && QuoteUtil.shouldShowGuide(getActivity(), guideResource)) {
                 guideView.setImageResource(guideResource);
                 maskLayer.setVisibility(View.VISIBLE);
               } else {
                 maskLayer.setVisibility(View.GONE);
               }
             }
           });
 }
Example #23
0
 /**
  * Returns the ID of a token for a given name.
  *
  * @param name the name of the token ID to get
  * @return a token ID
  */
 public static int getTokenId(String name) {
   final Integer id = TOKEN_NAME_TO_VALUE.get(name);
   if (id == null) {
     throw new IllegalArgumentException("Unknown javdoc token name. Given name " + name);
   }
   return id;
 }
Example #24
0
    /**
     * Populates an entity from a row.
     *
     * @param entity Entity object to populate from a row.
     * @param row Kiji row to populate the entity from.
     * @return the populated entity.
     * @throws IllegalAccessException
     * @throws IOException
     */
    public T populateEntityFromRow(T entity, KijiRowData row)
        throws IllegalAccessException, IOException {

      // Populate fields from the row columns:
      for (final Field field : mColumnFields) {
        final KijiColumn column = field.getAnnotation(KijiColumn.class);
        Preconditions.checkState(column != null);

        if (column.qualifier().isEmpty()) {
          // Field is populated from a map-type family:
          populateFieldFromMapTypeFamily(entity, field, column, row);

        } else {
          // Field is populated from a fully-qualified column:
          populateFieldFromFullyQualifiedColumn(entity, field, column, row);
        }
      }

      // Populate fields from the row entity ID:
      for (final Field field : mEntityIdFields) {
        final EntityIdField eidField = field.getAnnotation(EntityIdField.class);
        Preconditions.checkState(eidField != null);

        final int index = mRowKeyComponentIndexMap.get(eidField.component());
        field.set(entity, row.getEntityId().getComponentByIndex(index));
      }
      return entity;
    }
 @Test(dataProvider = "name")
 public void test_extendedEnum(ThreeLegBasisSwapConvention convention, String name) {
   ThreeLegBasisSwapConvention.of(name); // ensures map is populated
   ImmutableMap<String, ThreeLegBasisSwapConvention> map =
       ThreeLegBasisSwapConvention.extendedEnum().lookupAll();
   assertEquals(map.get(name), convention);
 }
Example #26
0
 public static Type form(String name) {
   Type type = typeMap.get(name);
   if (type == null) {
     return OTHER;
   }
   return type;
 }
Example #27
0
  @Test
  public void shouldBePossibleToCreateMap() {
    ImmutableMap<String, Address> map = addressMapBuilder().asAddressMap();

    assertThat(map.get("a").isFromUppsala(), is(true));
    assertThat(map.get("b").isFromUppsala(), is(false));
  }
Example #28
0
 public Executor executor(String name) {
   Executor executor = executors.get(name).executor;
   if (executor == null) {
     throw new ElasticSearchIllegalArgumentException("No executor found for [" + name + "]");
   }
   return executor;
 }
Example #29
0
  public void updateSettings(Settings settings) {
    Map<String, Settings> groupSettings = settings.getGroups("threadpool");
    if (groupSettings.isEmpty()) {
      return;
    }

    for (Map.Entry<String, Settings> executor : defaultExecutorTypeSettings.entrySet()) {
      Settings updatedSettings = groupSettings.get(executor.getKey());
      if (updatedSettings == null) {
        continue;
      }

      ExecutorHolder oldExecutorHolder = executors.get(executor.getKey());
      ExecutorHolder newExecutorHolder =
          rebuild(executor.getKey(), oldExecutorHolder, updatedSettings, executor.getValue());
      if (!oldExecutorHolder.equals(newExecutorHolder)) {
        executors =
            newMapBuilder(executors).put(executor.getKey(), newExecutorHolder).immutableMap();
        if (!oldExecutorHolder.executor.equals(newExecutorHolder.executor)
            && oldExecutorHolder.executor instanceof EsThreadPoolExecutor) {
          retiredExecutors.add(oldExecutorHolder);
          ((EsThreadPoolExecutor) oldExecutorHolder.executor)
              .shutdown(new ExecutorShutdownListener(oldExecutorHolder));
        }
      }
    }
  }
 /** Can this node become master or not. */
 public boolean masterNode() {
   String master = attributes.get("master");
   if (master == null) {
     return !clientNode();
   }
   return master.equals("true");
 }