use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory in project midpoint by Evolveum.
the class ConnectorManager method discoverConnectors.
/**
* Lists local connectors and makes sure that appropriate ConnectorType
* objects for them exist in repository.
*
* It will never delete any repository object, even if the corresponding
* connector cannot be found. The connector may temporarily removed, may be
* present on a different node, manual upgrade may be needed etc.
*
* @return set of discovered connectors (new connectors found)
* @throws CommunicationException
*/
// @SuppressWarnings("unchecked")
public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, OperationResult parentResult) throws CommunicationException {
OperationResult result = parentResult.createSubresult(ConnectorManager.class.getName() + ".discoverConnectors");
result.addParam("host", hostType);
// it
if (hostType != null && hostType.getOid() == null) {
throw new SystemException("Discovery attempt with non-persistent " + hostType);
}
Set<ConnectorType> discoveredConnectors = new HashSet<ConnectorType>();
for (ConnectorFactory connectorFactory : getConnectorFactories()) {
Set<ConnectorType> foundConnectors;
try {
foundConnectors = connectorFactory.listConnectors(hostType, result);
} catch (CommunicationException ex) {
result.recordFatalError("Discovery failed: " + ex.getMessage(), ex);
throw new CommunicationException("Discovery failed: " + ex.getMessage(), ex);
}
if (foundConnectors == null) {
LOGGER.trace("Connector factory {} discovered null connectors, skipping", connectorFactory);
continue;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Got {} connectors from {}: {}", new Object[] { foundConnectors.size(), hostType, foundConnectors });
}
for (ConnectorType foundConnector : foundConnectors) {
LOGGER.trace("Found connector {}", foundConnector);
boolean inRepo = true;
try {
inRepo = isInRepo(foundConnector, result);
} catch (SchemaException e1) {
LOGGER.error("Unexpected schema problem while checking existence of " + ObjectTypeUtil.toShortString(foundConnector), e1);
result.recordPartialError("Unexpected schema problem while checking existence of " + ObjectTypeUtil.toShortString(foundConnector), e1);
// But continue otherwise ...
}
if (!inRepo) {
LOGGER.trace("Connector {} not in the repository, \"dicovering\" it", foundConnector);
// itself
if (hostType != null && foundConnector.getConnectorHost() == null) {
foundConnector.setConnectorHost(hostType);
}
if (foundConnector.getSchema() == null) {
LOGGER.warn("Connector {} haven't provided configuration schema", foundConnector);
}
// Sanitize framework-supplied OID
if (StringUtils.isNotEmpty(foundConnector.getOid())) {
LOGGER.warn("Provisioning framework " + foundConnector.getFramework() + " supplied OID for connector " + ObjectTypeUtil.toShortString(foundConnector));
foundConnector.setOid(null);
}
// Store the connector object
String oid;
try {
prismContext.adopt(foundConnector);
oid = repositoryService.addObject(foundConnector.asPrismObject(), null, result);
} catch (ObjectAlreadyExistsException e) {
// We don't specify the OID, therefore this should never
// happen
// Convert to runtime exception
LOGGER.error("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
result.recordFatalError("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
} catch (SchemaException e) {
// If there is a schema error it must be a bug. Convert to
// runtime exception
LOGGER.error("Got SchemaException while not expecting it: " + e.getMessage(), e);
result.recordFatalError("Got SchemaException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e);
}
foundConnector.setOid(oid);
discoveredConnectors.add(foundConnector);
LOGGER.info("Discovered new connector " + foundConnector);
}
}
}
result.recordSuccess();
return discoveredConnectors;
}
use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory in project midpoint by Evolveum.
the class TestConnectorManager method test100ListConnectorFactories.
@Test
public void test100ListConnectorFactories() throws Exception {
final String TEST_NAME = "test100ListConnectorFactories";
TestUtil.displayTestTile(TEST_NAME);
OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName() + "." + TEST_NAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
Collection<ConnectorFactory> connectorFactories = connectorManager.getConnectorFactories();
// THEN
TestUtil.displayThen(TEST_NAME);
assertNotNull("Null connector factories", connectorFactories);
assertFalse("No connector factories found", connectorFactories.isEmpty());
display("Found " + connectorFactories.size() + " connector factories");
result.computeStatus();
TestUtil.assertSuccess(result);
for (ConnectorFactory connectorFactory : connectorFactories) {
display("Found connector factory " + connectorFactory, connectorFactory);
}
PrismAsserts.assertEqualsUnordered("Wrong connector factories", connectorFactories.stream().map(x -> x.getClass().getName()), "com.evolveum.midpoint.provisioning.ucf.impl.connid.ConnectorFactoryConnIdImpl", "com.evolveum.midpoint.provisioning.ucf.impl.builtin.ConnectorFactoryBuiltinImpl");
}
use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory in project midpoint by Evolveum.
the class ConnectorManager method getConnectorFactories.
public Collection<ConnectorFactory> getConnectorFactories() {
if (connectorFactories == null) {
String[] connectorFactoryBeanNames = springContext.getBeanNamesForType(ConnectorFactory.class);
LOGGER.debug("Connector factories bean names: {}", Arrays.toString(connectorFactoryBeanNames));
if (connectorFactoryBeanNames == null) {
return null;
}
connectorFactories = new ArrayList<>(connectorFactoryBeanNames.length);
for (String connectorFactoryBeanName : connectorFactoryBeanNames) {
Object bean = springContext.getBean(connectorFactoryBeanName);
if (bean instanceof ConnectorFactory) {
connectorFactories.add((ConnectorFactory) bean);
} else {
LOGGER.error("Bean {} is not instance of ConnectorFactory, it is {}, skipping", connectorFactoryBeanName, bean.getClass());
}
}
}
return connectorFactories;
}
use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory in project midpoint by Evolveum.
the class ConnectorManager method createConfiguredConnectorInstance.
private ConnectorInstance createConfiguredConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException {
ConnectorType connectorType = getConnectorTypeReadOnly(connectorSpec, result);
ConnectorFactory connectorFactory = determineConnectorFactory(connectorType);
ConnectorInstance connector = null;
try {
connector = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(connectorSpec.getResource()), connectorSpec.toString());
} catch (ObjectNotFoundException e) {
result.recordFatalError(e.getMessage(), e);
throw new ObjectNotFoundException(e.getMessage(), e);
}
PrismContainerValue<ConnectorConfigurationType> connectorConfigurationVal = connectorSpec.getConnectorConfiguration().getValue();
if (connectorConfigurationVal == null) {
SchemaException e = new SchemaException("No connector configuration in " + connectorSpec);
result.recordFatalError(e);
throw e;
}
try {
connector.configure(connectorConfigurationVal, result);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(connectorSpec.getResource(), prismContext);
Collection<Object> capabilities = ResourceTypeUtil.getNativeCapabilitiesCollection(connectorSpec.getResource().asObjectable());
connector.initialize(resourceSchema, capabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), result);
InternalMonitor.recordConnectorInstanceInitialization();
} catch (GenericFrameworkException e) {
// Not expected. Transform to system exception
result.recordFatalError("Generic provisioning framework error", e);
throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
} catch (CommunicationException e) {
result.recordFatalError(e);
throw e;
} catch (ConfigurationException e) {
result.recordFatalError(e);
throw 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;
}
Aggregations