public static PrismContainerDefinition<ConnectorConfigurationType> findConfigurationContainerDefinition(ConnectorType connectorType, PrismSchema connectorSchema) { QName configContainerQName = new QName(connectorType.getNamespace(), ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart()); return connectorSchema.findContainerDefinitionByElementName(configContainerQName); }
private void determineConnectorMappings(Map<String,String> rebindMap, ConnectorType connectorType, ExecutionContext context, OperationResult result) throws ScriptExecutionException { LOGGER.trace("Finding obsolete versions for connector: {}", connectorType.asPrismObject().debugDump()); .item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(connectorType.getFramework()) .and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(connectorType.getConnectorType()) .build(); List<PrismObject<ConnectorType>> foundConnectors; foundConnectors = modelService.searchObjects(ConnectorType.class, query, null, null, result); } catch (SchemaException|ConfigurationException|ObjectNotFoundException|CommunicationException|SecurityViolationException|ExpressionEvaluationException e) { throw new ScriptExecutionException("Couldn't get connectors of type: " + connectorType.getConnectorType() + ": " + e.getMessage(), e); ConnectorType foundConnectorType = foundConnector.asObjectable(); if (connectorType.getConnectorHost() != null) { if (foundConnectorType.getConnectorHost() == null) { connectorType.setConnectorHostRef(ObjectTypeUtil.createObjectRef(connectorType.getConnectorHost().getOid(), ObjectTypes.CONNECTOR_HOST)); connectorType.setConnectorHost(null); if (connectorType.getConnectorHostRef().equals(foundConnectorType.getConnectorHostRef()) && foundConnectorType.getConnectorVersion() != null && !foundConnectorType.getConnectorVersion().equals(connectorType.getConnectorVersion())) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Found obsolete connector: {}", foundConnectorType.asPrismObject().debugDump()); rebindMap.put(foundConnectorType.getOid(), connectorType.getOid());
public static PrismSchema getConnectorSchema(ConnectorType connectorType, PrismContext prismContext) throws SchemaException { XmlSchemaType xmlSchema = connectorType.getSchema(); if (xmlSchema == null) { return null; } Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchema); if (xsdElement == null) { return null; } MutablePrismSchema connectorSchema = prismContext.schemaFactory().createPrismSchema(); connectorSchema.parseThis(xsdElement, true, connectorType.toString(), prismContext); return connectorSchema; }
public ConnectorType clone() { ConnectorType object = new ConnectorType(); PrismObject value = asPrismObject().clone(); object.setupContainer(value); return object; }
private ConnectorKey getConnectorKey(ConnectorType connectorType) { return new ConnectorKey(connectorType.getConnectorBundle(), connectorType.getConnectorVersion(), connectorType.getConnectorType()); }
public static String getConnectorHostTypeOid(ConnectorType connectorType) { if (connectorType.getConnectorHostRef() != null) { return connectorType.getConnectorHostRef().getOid(); } else if (connectorType.getConnectorHost() != null) { return connectorType.getConnectorHost().getOid(); } else { return null; } }
public static void copyFromJAXB(ConnectorType jaxb, RConnector repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException { copyAssignmentHolderInformationFromJAXB(jaxb, repo, repositoryContext, generatorResult); repo.setNameCopy(RPolyString.copyFromJAXB(jaxb.getName())); repo.setConnectorBundle(jaxb.getConnectorBundle()); repo.setConnectorType(jaxb.getConnectorType()); repo.setConnectorVersion(jaxb.getConnectorVersion()); repo.setFramework(jaxb.getFramework()); repo.setConnectorHostRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getConnectorHostRef(), repositoryContext.relationRegistry)); if (jaxb.getConnectorHost() != null) { LOGGER.warn("Connector host from connector type won't be saved. It should be " + "translated to connector host reference."); } try { repo.setTargetSystemType(RUtil.listToSet(jaxb.getTargetSystemType())); } catch (Exception ex) { throw new DtoTranslationException(ex.getMessage(), ex); } } }
LOGGER.trace("Connector {} not in the repository, adding", foundConnector); if (foundConnector.getSchema() == null) { LOGGER.warn("Connector {} haven't provided configuration schema", foundConnector); if (StringUtils.isNotEmpty(foundConnector.getOid())) { LOGGER.warn("Provisioning framework {} supplied OID for connector {}", foundConnector.getFramework(), foundConnector); foundConnector.setOid(null); try { prismContext.adopt(foundConnector); oid = repositoryService.addObject(foundConnector.asPrismObject(), null, result); } catch (ObjectAlreadyExistsException e) { throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e); foundConnector.setOid(oid); if (hostType != null && foundConnector.getConnectorHost() == null) { foundConnector.setConnectorHost(hostType);
private boolean compareConnectors(PrismObject<ConnectorType> prismA, PrismObject<ConnectorType> prismB) { ConnectorType a = prismA.asObjectable(); ConnectorType b = prismB.asObjectable(); if (!a.getFramework().equals(b.getFramework())) { return false; } if (!a.getConnectorType().equals(b.getConnectorType())) { return false; } if (!compareConnectorHost(a, b)) { return false; } if (a.getConnectorVersion() == null && b.getConnectorVersion() == null) { // Both connectors without version. This is OK. return true; } if (a.getConnectorVersion() != null && b.getConnectorVersion() != null) { // Both connectors with version. This is OK. return a.getConnectorVersion().equals(b.getConnectorVersion()); } // One connector has version and other does not. This is inconsistency LOGGER.error("Inconsistent representation of ConnectorType, one has connectorVersion and other does not. OIDs: " + a.getOid() + " and " + b.getOid()); // Obviously they don't match return false; }
ConnectorType connectorType = new ConnectorType(); ConnectorKey key = cinfo.getConnectorKey(); UcfUtil.addConnectorNames(connectorType, "ConnId", key.getBundleName(), key.getConnectorName(), key.getBundleVersion(), hostType); String stringID = keyToNamespaceSuffix(key); connectorType.setFramework(SchemaConstants.ICF_FRAMEWORK_URI); connectorType.setConnectorType(key.getConnectorName()); connectorType.setNamespace(ICF_CONFIGURATION_NAMESPACE_PREFIX + stringID); connectorType.setConnectorVersion(key.getBundleVersion()); connectorType.setConnectorBundle(key.getBundleName()); if (hostType != null) { if (hostType.getOid() != null) { ref.setOid(hostType.getOid()); ref.setType(ObjectTypes.CONNECTOR_HOST.getTypeQName()); connectorType.setConnectorHostRef(ref); } else { connectorType.setConnectorHost(hostType);
private ConnectorStruct createConnectorStruct(Class connectorClass, ManagedConnector annotation) throws ObjectNotFoundException, SchemaException { ConnectorStruct struct = new ConnectorStruct(); struct.connectorClass = connectorClass; ConnectorType connectorType = new ConnectorType(); String bundleName = connectorClass.getPackage().getName(); String type = annotation.type(); if (type == null || type.isEmpty()) { type = connectorClass.getSimpleName(); } String version = annotation.version(); UcfUtil.addConnectorNames(connectorType, "Built-in", bundleName, type, version, null); connectorType.setConnectorBundle(bundleName); connectorType.setConnectorType(type); connectorType.setVersion(version); connectorType.setFramework(SchemaConstants.UCF_FRAMEWORK_URI_BUILTIN); String namespace = CONFIGURATION_NAMESPACE_PREFIX + bundleName + "/" + type; connectorType.setNamespace(namespace); struct.connectorObject = connectorType; PrismSchema connectorSchema = generateConnectorConfigurationSchema(struct); if (connectorSchema != null) { LOGGER.trace("Generated connector schema for {}: {} definitions", connectorType, connectorSchema.getDefinitions().size()); UcfUtil.setConnectorSchema(connectorType, connectorSchema); struct.connectorConfigurationSchema = connectorSchema; } else { LOGGER.warn("No connector schema generated for {}", connectorType); } return struct; }
ObjectTypeUtil.toShortString(connectorType)); LOGGER.trace("Connector object: {}", ObjectTypeUtil.dump(connectorType)); LOGGER.trace("Connector host object: {}", ObjectTypeUtil.dump(connectorType.getConnectorHost())); throw new ObjectNotFoundException("The classes (JAR) of " + ObjectTypeUtil.toShortString(connectorType) + " were not found by the ICF framework; bundle="+connectorType.getConnectorBundle()+" connector type=" + connectorType.getConnectorType() + ", version="+connectorType.getConnectorVersion());
XmlSchemaType xmlSchemaType = conn.getSchema(); assertNotNull("xmlSchemaType is null", xmlSchemaType); Element connectorXsdSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(conn); QName configurationElementQname = new QName(conn.getNamespace(), ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart()); PrismContainerDefinition configurationContainer = schema .findContainerDefinitionByElementName(configurationElementQname);
} else { String currentConnectorVersion = repositoryService.getVersion(ConnectorType.class, connOid, result); if (!currentConnectorVersion.equals(connectorType.getVersion())) { Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createReadOnly()); PrismObject<ConnectorType> repoConnector = repositoryService.getObject(ConnectorType.class, connOid, options, result); if (connectorType.getConnectorHost() == null && connectorType.getConnectorHostRef() != null) { String connectorHostOid = connectorType.getConnectorHostRef().getOid(); PrismObject<ConnectorHostType> connectorHost = repositoryService.getObject(ConnectorHostType.class, connectorHostOid, null, result); connectorType.setConnectorHost(connectorHost.asObjectable()); PrismObject<ConnectorType> connector = connectorType.asPrismObject(); Object userDataEntry = connector.getUserData(USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA); if (userDataEntry == null) {
PrismAsserts.assertEqualsPolyString("Wrong connector name.", "ICF org.identityconnectors.databasetable.DatabaseTableConnector", connector.getName()); assertEquals(CONNECTOR_NAMESPACE, connector.getNamespace()); assertEquals("org.identityconnectors.databasetable.DatabaseTableConnector", connector.getConnectorType());
public static void assertConnectorSchemaSanity(ConnectorType conn, PrismContext prismContext) throws SchemaException { XmlSchemaType xmlSchemaType = conn.getSchema(); assertNotNull("xmlSchemaType is null",xmlSchemaType); Element connectorXsdSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(conn); assertNotNull("No schema", connectorXsdSchemaElement); Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaType); assertNotNull("No xsd:schema element in xmlSchemaType",xsdElement); display("XSD schema of "+conn, DOMUtil.serializeDOMToString(xsdElement)); // Try to parse the schema PrismSchema schema = null; try { schema = PrismSchemaImpl.parse(xsdElement, true, "schema of "+conn, prismContext); } catch (SchemaException e) { throw new SchemaException("Error parsing schema of "+conn+": "+e.getMessage(),e); } assertConnectorSchemaSanity(schema, conn.toString(), SchemaConstants.ICF_FRAMEWORK_URI.equals(conn.getFramework())); }
if (hostType == null) { query = prismContext.queryFor(ConnectorType.class) .item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(connectorType.getFramework()) .and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(connectorType.getConnectorType()) .and().item(ConnectorType.F_CONNECTOR_HOST_REF).isNull() .build(); } else { query = prismContext.queryFor(ConnectorType.class) .item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(connectorType.getFramework()) .and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(connectorType.getConnectorType()) .and().item(ConnectorType.F_CONNECTOR_HOST_REF).ref(hostType.getOid(), ConnectorHostType.COMPLEX_TYPE) .build(); if (compareConnectors(connectorType.asPrismObject(), foundConnector)) { if (foundOid != null) { result.recordPartialError("Found more than one connector that matches " + connectorType.getFramework() + " : " + connectorType.getConnectorType() + " : " + connectorType.getVersion() + ". OIDs " + foundConnector.getOid() + " and " + foundOid + ". Inconsistent database state."); LOGGER.error("Found more than one connector that matches " + connectorType.getFramework() + " : " + connectorType.getConnectorType() + " : " + connectorType.getVersion() + ". OIDs " + foundConnector.getOid() + " and " + foundOid + ". Inconsistent database state.");
/** * Get contect informations * * @param connectorType * @return * @throws ObjectNotFoundException */ private ConnectorInfo getConnectorInfo(ConnectorType connectorType) throws ObjectNotFoundException { if (!SchemaConstants.ICF_FRAMEWORK_URI.equals(connectorType.getFramework())) { throw new ObjectNotFoundException("Requested connector for framework " + connectorType.getFramework() + " cannot be found in framework " + SchemaConstants.ICF_FRAMEWORK_URI); } ConnectorKey key = getConnectorKey(connectorType); if (connectorType.getConnectorHost() == null && connectorType.getConnectorHostRef() == null) { // Local connector return getLocalConnectorInfoManager().findConnectorInfo(key); } ConnectorHostType host = connectorType.getConnectorHost(); if (host == null) { throw new ObjectNotFoundException( "Attempt to use remote connector without ConnectorHostType resolved (there is only ConnectorHostRef"); } return getRemoteConnectorInfoManager(host).findConnectorInfo(key); }
@Test public void testListConnectors() throws Exception{ TestUtil.displayTestTitle("testListConnectors"); OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName() + ".listConnectorsTest"); List<PrismObject<ConnectorType>> connectors = provisioningService.searchObjects(ConnectorType.class, null, null, null, result); assertNotNull(connectors); for (PrismObject<ConnectorType> connector : connectors){ ConnectorType conn = connector.asObjectable(); System.out.println(conn.toString()); System.out.println("connector name: "+ conn.getName()); System.out.println("connector type: "+ conn.getConnectorType()); System.out.println("-----\n"); } assertEquals("Unexpected number of connectors found", 8, connectors.size()); }
private ConnectorInstance createConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException { ConnectorType connectorType = getConnectorTypeReadOnly(connectorSpec, result); ConnectorFactory connectorFactory = determineConnectorFactory(connectorType); ConnectorInstance connector = null; try { InternalMonitor.recordCount(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT); connector = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(connectorSpec.getResource()), connectorSpec.getResource().getName().toString(), connectorSpec.toString()); } catch (ObjectNotFoundException e) { result.recordFatalError(e.getMessage(), e); throw new ObjectNotFoundException(e.getMessage(), e); } // This log message should be INFO level. It happens only occasionally. // If it happens often, it may be an // indication of a problem. Therefore it is good for admin to see it. LOGGER.info("Created new connector instance for {}: {} v{}", connectorSpec, connectorType.getConnectorType(), connectorType.getConnectorVersion()); return connector; }