@Test(expected = IllegalArgumentException.class) public void forbidDuplicatedType() { ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("TRK").build()) .build(); }
/** * Extract the id from a resource_type element and add to the resource map. Also extract the ids * from any contained method and its representation or fault elements. * * @param file the URI of the current WADL file being processed * @param r the resource_type element * @throws javax.xml.bind.JAXBException if the WADL file is invalid or if the code generator * encounters a problem. * @throws java.io.IOException if the specified WADL file cannot be read. */ protected void extractResourceTypeIds(ResourceType r, URI file) throws JAXBException, IOException { String id = processIDHref(file, r.getId(), null, r); if (id != null) ifaceMap.put(id, null); for (Method child : r.getMethod()) { extractMethodIds((Method) child, file); } }
public static String getValueByCode(String code) { for (ResourceType c : ResourceType.values()) { if (c.getCode().equals(code)) { return c.value; } } return null; }
@Test(expected = IllegalArgumentException.class) public void forbidNullRelation() { ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("DIR").build()) .addRelations("DIR" /* missing child */) .build(); }
public class ResourceTypeTreeTest { private final ResourceTypeTree tree = ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("DIR").build()) .addType(ResourceType.builder("FIL").build()) .addType(ResourceType.builder("UTS").build()) .addRelations("TRK", "DIR") .addRelations("DIR", "FIL") .addRelations("DIR", "UTS") .build(); @Test public void getTypes() { assertThat(tree.getTypes().size(), is(4)); assertThat(qualifiers(tree.getTypes()), hasItems("TRK", "DIR", "FIL", "UTS")); } @Test public void getChildren() { assertThat(tree.getChildren("TRK").size(), is(1)); assertThat(tree.getChildren("TRK"), hasItems("DIR")); assertThat(tree.getChildren("DIR").size(), is(2)); assertThat(tree.getChildren("DIR"), hasItems("FIL", "UTS")); assertThat(tree.getChildren("FIL").size(), is(0)); } @Test public void getRoot() { assertThat(tree.getRootType(), is(ResourceType.builder("TRK").build())); } @Test public void getLeaves() { assertThat(tree.getLeaves().size(), is(2)); assertThat(tree.getLeaves(), hasItems("FIL", "UTS")); } @Test(expected = IllegalArgumentException.class) public void forbidNullRelation() { ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("DIR").build()) .addRelations("DIR" /* missing child */) .build(); } @Test(expected = IllegalArgumentException.class) public void forbidDuplicatedType() { ResourceTypeTree.builder() .addType(ResourceType.builder("TRK").build()) .addType(ResourceType.builder("TRK").build()) .build(); } }
public ResourceTypeTree build() { Collection<String> children = relations.values(); for (ResourceType type : types) { if (!children.contains(type.getQualifier())) { root = type; break; } } return new ResourceTypeTree(this); }
public static ResourceType getFileType(String fileName) { for (ResourceType type : ResourceType.values()) { for (String ext : type.getExts()) { if (fileName.endsWith(ext)) { return type; } } } return UNKNOWN; }
public static void checkResourceType(ResourceType<?> resource) { // Check optional fields URI href = resource.getHref(); if (href != null) checkHref(href); String type = resource.getType(); if (type != null) checkType(type); Set<Link> links = resource.getLinks(); if (links != null && !links.isEmpty()) { for (Link link : links) checkLink(link); } }
/** * Build an abstract tree for a resource types in a WADL file * * @param ifaceId the identifier of the resource type * @param a the application element of the root WADL file */ protected void buildResourceTypes(String ifaceId, Application a) { try { URI file = new URI(ifaceId.substring(0, ifaceId.indexOf('#'))); ResourceType type = (ResourceType) idMap.get(ifaceId); ResourceTypeNode node = new ResourceTypeNode(type); for (Method m : type.getMethod()) { addMethodToResourceType(node, m, file); } ifaceMap.put(ifaceId, node); } catch (URISyntaxException ex) { ex.printStackTrace(); } }
/** * A comma-separated list that specifies the types of AWS resources for which AWS Config records * configuration changes (for example, <code>AWS::EC2::Instance</code> or <code> * AWS::CloudTrail::Trail</code>). * * <p>Before you can set this option to <code>true</code>, you must set the <code>allSupported * </code> option to <code>false</code>. * * <p>If you set this option to <code>true</code>, when AWS Config adds support for a new type of * resource, it will not record resources of that type unless you manually add that type to your * recording group. * * <p>For a list of valid <code>resourceTypes</code> values, see the <b>resourceType Value</b> * column in <a href= * "http://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html#supported-resources" * >Supported AWS Resource Types</a>. * * @param resourceTypes A comma-separated list that specifies the types of AWS resources for which * AWS Config records configuration changes (for example, <code>AWS::EC2::Instance</code> or * <code>AWS::CloudTrail::Trail</code>). * <p>Before you can set this option to <code>true</code>, you must set the <code>allSupported * </code> option to <code>false</code>. * <p>If you set this option to <code>true</code>, when AWS Config adds support for a new type * of resource, it will not record resources of that type unless you manually add that type to * your recording group. * <p>For a list of valid <code>resourceTypes</code> values, see the <b>resourceType Value</b> * column in <a href= * "http://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html#supported-resources" * >Supported AWS Resource Types</a>. * @return Returns a reference to this object so that method calls can be chained together. * @see ResourceType */ public RecordingGroup withResourceTypes(ResourceType... resourceTypes) { com.amazonaws.internal.SdkInternalList<String> resourceTypesCopy = new com.amazonaws.internal.SdkInternalList<String>(resourceTypes.length); for (ResourceType value : resourceTypes) { resourceTypesCopy.add(value.toString()); } if (getResourceTypes() == null) { setResourceTypes(resourceTypesCopy); } else { getResourceTypes().addAll(resourceTypesCopy); } return this; }
/** * Use this in place of valueOf. * * @param value real value * @return ResourceType corresponding to the value */ public static ResourceType fromValue(String value) { if (value == null || "".equals(value)) { throw new IllegalArgumentException("Value cannot be null or empty!"); } for (ResourceType enumEntry : ResourceType.values()) { if (enumEntry.toString().equals(value)) { return enumEntry; } } throw new IllegalArgumentException("Cannot create enum from " + value + " value!"); }
public boolean evaluateConfirmationExpression( UserType user, ShadowType shadow, ExpressionType expressionType, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException { Validate.notNull(user, "User must not be null."); Validate.notNull(shadow, "Resource object shadow must not be null."); Validate.notNull(expressionType, "Expression must not be null."); Validate.notNull(result, "Operation result must not be null."); ResourceType resource = resolveResource(shadow, result); ExpressionVariables variables = getDefaultXPathVariables(user, shadow, resource); String shortDesc = "confirmation expression for " + resource.asPrismObject(); PrismPropertyDefinition<Boolean> outputDefinition = new PrismPropertyDefinition<>( ExpressionConstants.OUTPUT_ELMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext); Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, shortDesc, task, result); ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, variables, shortDesc, task, result); PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext( expression, params, task, result); Collection<PrismPropertyValue<Boolean>> nonNegativeValues = outputTriple.getNonNegativeValues(); if (nonNegativeValues == null || nonNegativeValues.isEmpty()) { throw new ExpressionEvaluationException( "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc); } if (nonNegativeValues.size() > 1) { throw new ExpressionEvaluationException( "Expression returned more than one value (" + nonNegativeValues.size() + ") in " + shortDesc); } PrismPropertyValue<Boolean> resultpval = nonNegativeValues.iterator().next(); if (resultpval == null) { throw new ExpressionEvaluationException( "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc); } Boolean resultVal = resultpval.getValue(); if (resultVal == null) { throw new ExpressionEvaluationException( "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc); } return resultVal; }
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("<"); for (int i = 0; i < ResourceType.values().length; i++) { if (i != 0) { sb.append(", "); } ResourceType resourceType = ResourceType.values()[i]; sb.append(StringUtils.toLowerCase(resourceType.name())); sb.append(StringUtils.format(" weight=%.1f", getWeight(resourceType))); } sb.append(">"); return sb.toString(); }
/** * storeResult * * @param collectionSet a {@link org.opennms.netmgt.collectd.SnmpCollectionSet} object. * @param entry a {@link org.opennms.netmgt.collectd.SNMPCollectorEntry} object. * @param res a {@link org.opennms.netmgt.snmp.SnmpResult} object. */ public void storeResult( SnmpCollectionSet collectionSet, SNMPCollectorEntry entry, SnmpResult res) { LOG.debug("Setting attribute: {}.[{}] = '{}'", this, res.getInstance(), res.getValue()); SnmpCollectionResource resource = null; if (this.getAlias().equals("ifAlias")) { resource = m_resourceType.findAliasedResource(res.getInstance(), res.getValue().toString()); } else { resource = m_resourceType.findResource(res.getInstance()); } if (resource == null) { collectionSet.notifyIfNotFound(this, res); } else { resource.setAttributeValue(this, res.getValue()); } }
public void delete_resources(ResourceType t, List<String> value) { Set<String> resources = resource_map.get(t); if (resources != null && !resources.isEmpty()) { t.postHook(resources, value); resources.removeAll(value); } }
public Builder addType(ResourceType type) { Preconditions.checkNotNull(type); Preconditions.checkArgument( !types.contains(type), String.format("%s is already registered", type.getQualifier())); types.add(type); return this; }
/** * Simple call to connector test() method. * * @throws Exception */ @Test public void test310TestConnectionNegative() throws Exception { final String TEST_NAME = "test310TestConnectionNegative"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(TEST_NAME); ConnectorInstance badConnector = factory.createConnectorInstance( connectorType, ResourceTypeUtil.getResourceNamespace(badResourceType), "test connector"); badConnector.configure( badResourceType.getConnectorConfiguration().asPrismContainerValue(), result); // WHEN badConnector.test(result); // THEN result.computeStatus("test failed"); display("Test result (FAILURE EXPECTED)", result); AssertJUnit.assertNotNull(result); OperationResult connectorConnectionResult = result.getSubresults().get(1); AssertJUnit.assertNotNull(connectorConnectionResult); System.out.println( "Test \"connector connection\" result: " + connectorConnectionResult + " (FAILURE EXPECTED)"); AssertJUnit.assertTrue( "Unexpected success of bad connector test", !connectorConnectionResult.isSuccess()); AssertJUnit.assertTrue(!result.isSuccess()); }
public static void setParsedResourceSchemaConditional( ResourceType resourceType, ResourceSchema parsedSchema) { if (hasParsedSchema(resourceType)) { return; } PrismObject<ResourceType> resource = resourceType.asPrismObject(); resource.setUserData(USER_DATA_KEY_PARSED_RESOURCE_SCHEMA, parsedSchema); }
private CollectionTracker getCollectionTracker() { SnmpInstId[] instances = m_resourceType.getCollectionInstances(); if (instances != null && Boolean.getBoolean( "org.opennms.netmgt.collectd.SnmpCollector.limitCollectionToInstances")) { return getMibObj().getCollectionTracker(instances); } else { return getMibObj().getCollectionTracker(); } }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((address == null) ? 0 : address.hashCode()); result = prime * result + ((addressOnParent == null) ? 0 : addressOnParent.hashCode()); result = prime * result + ((resourceSubType == null) ? 0 : resourceSubType.hashCode()); result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); return result; }
private void addResourceTypes() throws IOException { RandomAccessFile f = new RandomAccessFile("randomResourceType.csv", "r"); String dataString = null; while ((dataString = f.readLine()) != null) { String[] data = dataString.split(";"); ResourceType insert = new ResourceType(); if (data[0].length() < 45) { insert.setResourceTypeName(data[0]); } else { insert.setResourceTypeName(data[0].substring(0, 44)); } System.out.println(insert); try { resourceTypeDAO.insertResourceType(insert); } catch (ResourceTypeNameExistsException e) { e.printStackTrace(); } } f.close(); }
public ResourceTypes(ResourceTypeTree[] trees) { Preconditions.checkNotNull(trees); Map<String, ResourceTypeTree> treeMap = Maps.newHashMap(); Map<String, ResourceType> typeMap = Maps.newLinkedHashMap(); Collection<ResourceType> rootsSet = Sets.newHashSet(); for (ResourceTypeTree tree : trees) { rootsSet.add(tree.getRootType()); for (ResourceType type : tree.getTypes()) { if (treeMap.containsKey(type.getQualifier())) { throw new IllegalStateException( "Qualifier " + type.getQualifier() + " is defined in several trees"); } treeMap.put(type.getQualifier(), tree); typeMap.put(type.getQualifier(), type); } } treeByQualifier = ImmutableMap.copyOf(treeMap); typeByQualifier = ImmutableMap.copyOf(typeMap); rootTypes = ImmutableList.copyOf(rootsSet); }
public static ResourceType find_resource_type(String s) { s = s.trim().toUpperCase(); try { return ResourceType.valueOf(s); } catch (IllegalArgumentException e) { } // try singular if (s.endsWith("S")) { s = s.substring(0, s.length() - 1); } else { return null; } try { return ResourceType.valueOf(s); } catch (IllegalArgumentException e) { } return null; }
@Override public int hashCode() { List<Object> list = new ArrayList<Object>(); boolean present_resourceType = true && (isSetResourceType()); list.add(present_resourceType); if (present_resourceType) list.add(resourceType.getValue()); boolean present_uri = true && (isSetUri()); list.add(present_uri); if (present_uri) list.add(uri); return list.hashCode(); }
@Private @Evolving public class ResourceWeights { public static final ResourceWeights NEUTRAL = new ResourceWeights(1.0f); private float[] weights = new float[ResourceType.values().length]; public ResourceWeights(float memoryWeight, float cpuWeight) { weights[ResourceType.MEMORY.ordinal()] = memoryWeight; weights[ResourceType.CPU.ordinal()] = cpuWeight; } public ResourceWeights(float weight) { setWeight(weight); } public ResourceWeights() {} public void setWeight(float weight) { for (int i = 0; i < weights.length; i++) { weights[i] = weight; } } public void setWeight(ResourceType resourceType, float weight) { weights[resourceType.ordinal()] = weight; } public float getWeight(ResourceType resourceType) { return weights[resourceType.ordinal()]; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append("<"); for (int i = 0; i < ResourceType.values().length; i++) { if (i != 0) { sb.append(", "); } ResourceType resourceType = ResourceType.values()[i]; sb.append(StringUtils.toLowerCase(resourceType.name())); sb.append(StringUtils.format(" weight=%.1f", getWeight(resourceType))); } sb.append(">"); return sb.toString(); } }
/** * Register a new application on the node * * @param node the node to register on * @param type the type of an application * @param appInfo the appInfo string for the application */ protected void addAppToNode(ClusterNode node, ResourceType type, String appInfo) { synchronized (node) { // Update primary index. Map<ResourceType, String> apps = nameToApps.get(node.getName()); apps.put(type, appInfo); // Update runnable indices. for (Map.Entry<ResourceType, RunnableIndices> entry : typeToIndices.entrySet()) { if (type.equals(entry.getKey())) { if (node.checkForGrant(Utilities.getUnitResourceRequest(type), resourceLimit)) { RunnableIndices r = entry.getValue(); r.addRunnable(node); } } } } }
public static ExpressionVariables getDefaultXPathVariables( UserType user, ShadowType shadow, ResourceType resource) { ExpressionVariables variables = new ExpressionVariables(); if (user != null) { variables.addVariableDefinition(ExpressionConstants.VAR_USER, user.asPrismObject()); } if (shadow != null) { variables.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, shadow.asPrismObject()); } if (resource != null) { variables.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, resource.asPrismObject()); } return variables; }
@BeforeMethod public void initUcf() throws Exception { TestUtil.displayTestTile("initUcf"); File file = new File(FILENAME_RESOURCE_OPENDJ); FileInputStream fis = new FileInputStream(file); // Resource PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(FILENAME_RESOURCE_OPENDJ)); resourceType = resource.asObjectable(); // Resource: Second copy for negative test cases PrismObject<ResourceType> badResource = PrismTestUtil.parseObject(new File(FILENAME_RESOURCE_OPENDJ_BAD)); badResourceType = badResource.asObjectable(); // Connector PrismObject<ConnectorType> connector = PrismTestUtil.parseObject(new File(FILENAME_CONNECTOR_LDAP)); connectorType = connector.asObjectable(); factory = connectorFactoryIcfImpl; cc = factory.createConnectorInstance( connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "test connector"); AssertJUnit.assertNotNull("Cannot create connector instance", cc); connectorSchema = cc.generateConnectorSchema(); AssertJUnit.assertNotNull("Cannot generate connector schema", cc); display("Connector schema", connectorSchema); OperationResult result = new OperationResult("initUcf"); cc.configure(resourceType.getConnectorConfiguration().asPrismContainerValue(), result); cc.initialize(null, null, false, result); // TODO: assert something resourceSchema = cc.fetchResourceSchema(null, result); display("Resource schema", resourceSchema); AssertJUnit.assertNotNull(resourceSchema); }
public static RefinedResourceSchema parse(ResourceType resourceType, PrismContext prismContext) throws SchemaException { ResourceSchema originalResourceSchema = getResourceSchema(resourceType, prismContext); if (originalResourceSchema == null) { return null; } String contextDescription = "definition of " + resourceType; RefinedResourceSchemaImpl rSchema = new RefinedResourceSchemaImpl(originalResourceSchema); SchemaHandlingType schemaHandling = resourceType.getSchemaHandling(); if (schemaHandling != null) { parseObjectTypeDefsFromSchemaHandling( rSchema, resourceType, schemaHandling, schemaHandling.getObjectType(), null, prismContext, contextDescription); } parseObjectTypesFromSchema(rSchema, resourceType, prismContext, contextDescription); // We need to parse associations and auxiliary object classes in a second pass. We need to have // all object classes parsed before correctly setting association // targets for (RefinedObjectClassDefinition rOcDef : rSchema.getRefinedDefinitions()) { ((RefinedObjectClassDefinitionImpl) rOcDef).parseAssociations(rSchema); ((RefinedObjectClassDefinitionImpl) rOcDef).parseAuxiliaryObjectClasses(rSchema); } // We can parse attributes only after we have all the object class info parsed (including // auxiliary object classes) for (RefinedObjectClassDefinition rOcDef : rSchema.getRefinedDefinitions()) { ((RefinedObjectClassDefinitionImpl) rOcDef).parseAttributes(rSchema, contextDescription); } return rSchema; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ResourceAllocationSettingData other = (ResourceAllocationSettingData) obj; if (address == null) { if (other.address != null) return false; } else if (!address.equals(other.address)) return false; if (addressOnParent == null) { if (other.addressOnParent != null) return false; } else if (!addressOnParent.equals(other.addressOnParent)) return false; if (resourceSubType == null) { if (other.resourceSubType != null) return false; } else if (!resourceSubType.equals(other.resourceSubType)) return false; if (resourceType == null) { if (other.resourceType != null) return false; } else if (!resourceType.equals(other.resourceType)) return false; return true; }