Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 23, 2018
2 parents 8a6f81d + 0e5eed7 commit 18e4df9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 40 deletions.
Expand Up @@ -58,6 +58,7 @@
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
Expand Down Expand Up @@ -389,8 +390,7 @@ public Set<ConnectorType> discoverLocalConnectors(OperationResult parentResult)
public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, OperationResult parentResult)
throws CommunicationException {

OperationResult result = parentResult.createSubresult(ConnectorManager.class.getName()
+ ".discoverConnectors");
OperationResult result = parentResult.createSubresult(ConnectorManager.class.getName() + ".discoverConnectors");
result.addParam("host", hostType);

// Make sure that the provided host has an OID.
Expand Down Expand Up @@ -420,45 +420,36 @@ public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, Operati
}

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Got {} connectors from {}: {}", new Object[] { foundConnectors.size(), hostType, foundConnectors });
LOGGER.trace("Got {} connectors from {}: {}", foundConnectors.size(), hostType, foundConnectors );
}

for (ConnectorType foundConnector : foundConnectors) {

LOGGER.trace("Found connector {}", foundConnector);
LOGGER.trace("Examining connector {}", foundConnector);

boolean inRepo = true;
try {
inRepo = isInRepo(foundConnector, result);
inRepo = isInRepo(foundConnector, hostType, result);
} catch (SchemaException e1) {
LOGGER.error(
"Unexpected schema problem while checking existence of "
+ ObjectTypeUtil.toShortString(foundConnector), e1);
"Unexpected schema problem while checking existence of {}", foundConnector, e1);
result.recordPartialError(
"Unexpected schema problem while checking existence of "
+ ObjectTypeUtil.toShortString(foundConnector), e1);
"Unexpected schema problem while checking existence of " + foundConnector, e1);
// But continue otherwise ...
}
if (!inRepo) {

LOGGER.trace("Connector {} not in the repository, \"dicovering\" it", foundConnector);

// First of all we need to "embed" connectorHost to the
// connectorType. The UCF does not
// have access to repository, therefore it cannot resolve it for
// itself
if (hostType != null && foundConnector.getConnectorHost() == null) {
foundConnector.setConnectorHost(hostType);
}
if (inRepo) {
LOGGER.trace("Connector {} is in the repository, skipping", foundConnector);

} else {
LOGGER.trace("Connector {} not in the repository, adding", foundConnector);

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));
LOGGER.warn("Provisioning framework {} supplied OID for connector {}", foundConnector.getFramework(), foundConnector);
foundConnector.setOid(null);
}

Expand All @@ -471,21 +462,28 @@ public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, Operati
// 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);
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);
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);

// We need to "embed" connectorHost to the connectorType. The UCF does not
// have access to repository, therefore it cannot resolve it for itself
if (hostType != null && foundConnector.getConnectorHost() == null) {
foundConnector.setConnectorHost(hostType);
}

discoveredConnectors.add(foundConnector);
LOGGER.info("Discovered new connector " + foundConnector);
LOGGER.info("Discovered new connector {}", foundConnector);
}
}
}
Expand All @@ -494,14 +492,24 @@ public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, Operati
return discoveredConnectors;
}

private boolean isInRepo(ConnectorType connectorType, OperationResult result) throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(ConnectorType.class, prismContext)
.item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(connectorType.getFramework())
.and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(connectorType.getConnectorType())
.build();
private boolean isInRepo(ConnectorType connectorType, ConnectorHostType hostType, OperationResult result) throws SchemaException {
ObjectQuery query;
if (hostType == null) {
query = QueryBuilder.queryFor(ConnectorType.class, prismContext)
.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 = QueryBuilder.queryFor(ConnectorType.class, prismContext)
.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 (LOGGER.isTraceEnabled()) {
LOGGER.trace("Looking for connector in repository:\n{}", query.debugDump());
LOGGER.trace("Looking for connector in repository:\n{}", query.debugDump(1));
}

List<PrismObject<ConnectorType>> foundConnectors;
Expand All @@ -513,6 +521,10 @@ private boolean isInRepo(ConnectorType connectorType, OperationResult result) th
result.recordFatalError("Got SchemaException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e);
}

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Found repository connectors:\n{}", DebugUtil.debugDump(foundConnectors, 1));
}

if (foundConnectors.size() == 0) {
// Nothing found, the connector is not in the repo
Expand Down Expand Up @@ -549,14 +561,8 @@ private boolean compareConnectors(PrismObject<ConnectorType> prismA, PrismObject
if (!a.getConnectorType().equals(b.getConnectorType())) {
return false;
}
if (a.getConnectorHostRef() != null) {
if (!a.getConnectorHostRef().equals(b.getConnectorHostRef())) {
return false;
}
} else {
if (b.getConnectorHostRef() != null) {
return false;
}
if (!compareConnectorHost(a, b)) {
return false;
}
if (a.getConnectorVersion() == null && b.getConnectorVersion() == null) {
// Both connectors without version. This is OK.
Expand All @@ -573,7 +579,17 @@ private boolean compareConnectors(PrismObject<ConnectorType> prismA, PrismObject
return false;
}

public String getFrameworkVersion() {
private boolean compareConnectorHost(ConnectorType a, ConnectorType b) {
if (a.getConnectorHostRef() == null && b.getConnectorHostRef() == null) {
return true;
}
if (a.getConnectorHostRef() == null || b.getConnectorHostRef() == null) {
return false;
}
return a.getConnectorHostRef().getOid().equals(b.getConnectorHostRef().getOid());
}

public String getFrameworkVersion() {
ConnectorFactory connectorFactory = determineConnectorFactory(SchemaConstants.ICF_FRAMEWORK_URI);
return connectorFactory.getFrameworkVersion();
}
Expand Down
Expand Up @@ -88,6 +88,9 @@ public class ConnectorFactoryBuiltinImpl implements ConnectorFactory {
@Override
public Set<ConnectorType> listConnectors(ConnectorHostType host, OperationResult parentRestul)
throws CommunicationException {
if (host != null) {
return null;
}
if (connectorMap == null) {
discoverConnectors();
}
Expand Down

0 comments on commit 18e4df9

Please sign in to comment.