Search in sources :

Example 1 with ProvisioningScriptType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType in project midpoint by Evolveum.

the class ProvisioningUtil method convertToScriptOperation.

public static ExecuteProvisioningScriptOperation convertToScriptOperation(ProvisioningScriptType scriptType, String desc, PrismContext prismContext) throws SchemaException {
    ExecuteProvisioningScriptOperation scriptOperation = new ExecuteProvisioningScriptOperation();
    PrismPropertyDefinition scriptArgumentDefinition = new PrismPropertyDefinitionImpl(FAKE_SCRIPT_ARGUMENT_NAME, DOMUtil.XSD_STRING, prismContext);
    for (ProvisioningScriptArgumentType argument : scriptType.getArgument()) {
        ExecuteScriptArgument arg = new ExecuteScriptArgument(argument.getName(), StaticExpressionUtil.getStaticOutput(argument, scriptArgumentDefinition, desc, ExpressionReturnMultiplicityType.SINGLE, prismContext));
        scriptOperation.getArgument().add(arg);
    }
    scriptOperation.setLanguage(scriptType.getLanguage());
    scriptOperation.setTextCode(scriptType.getCode());
    if (scriptType.getHost() != null && scriptType.getHost().equals(ProvisioningScriptHostType.CONNECTOR)) {
        scriptOperation.setConnectorHost(true);
        scriptOperation.setResourceHost(false);
    }
    if (scriptType.getHost() == null || scriptType.getHost().equals(ProvisioningScriptHostType.RESOURCE)) {
        scriptOperation.setConnectorHost(false);
        scriptOperation.setResourceHost(true);
    }
    return scriptOperation;
}
Also used : ExecuteScriptArgument(com.evolveum.midpoint.provisioning.ucf.api.ExecuteScriptArgument) ExecuteProvisioningScriptOperation(com.evolveum.midpoint.provisioning.ucf.api.ExecuteProvisioningScriptOperation) ProvisioningScriptArgumentType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptArgumentType)

Example 2 with ProvisioningScriptType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType in project midpoint by Evolveum.

the class ResourceManager method executeScript.

public Object executeScript(String resourceOid, ProvisioningScriptType script, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    PrismObject<ResourceType> resource = getResource(resourceOid, null, task, result);
    ConnectorSpec connectorSpec = selectConnectorSpec(resource, ScriptCapabilityType.class);
    if (connectorSpec == null) {
        throw new UnsupportedOperationException("No connector supports script capability");
    }
    ConnectorInstance connectorInstance = connectorManager.getConfiguredConnectorInstance(connectorSpec, false, result);
    ExecuteProvisioningScriptOperation scriptOperation = ProvisioningUtil.convertToScriptOperation(script, "script on " + resource, prismContext);
    try {
        StateReporter reporter = new StateReporter(resourceOid, task);
        return connectorInstance.executeScript(scriptOperation, reporter, result);
    } 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);
    }
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ExecuteProvisioningScriptOperation(com.evolveum.midpoint.provisioning.ucf.api.ExecuteProvisioningScriptOperation) StateReporter(com.evolveum.midpoint.task.api.StateReporter)

Example 3 with ProvisioningScriptType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType in project midpoint by Evolveum.

the class TestDummy method test135ExecuteScript.

@Test
public void test135ExecuteScript() throws Exception {
    final String TEST_NAME = "test135ExecuteScript";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    syncServiceMock.reset();
    dummyResource.purgeScriptHistory();
    OperationProvisioningScriptsType scriptsType = unmarshallValueFromFile(SCRIPTS_FILE, OperationProvisioningScriptsType.class);
    display("Provisioning scripts", PrismTestUtil.serializeAnyDataWrapped(scriptsType));
    ProvisioningScriptType script = scriptsType.getScript().get(0);
    // WHEN
    provisioningService.executeScript(RESOURCE_DUMMY_OID, script, task, result);
    // THEN
    result.computeStatus();
    display("executeScript result", result);
    TestUtil.assertSuccess("executeScript has failed (result)", result);
    ProvisioningScriptSpec expectedScript = new ProvisioningScriptSpec("Where to go now?");
    expectedScript.addArgMulti("direction", "left", "right");
    IntegrationTestTools.assertScripts(dummyResource.getScriptHistory(), expectedScript);
    assertSteadyResource();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationProvisioningScriptsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationProvisioningScriptsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProvisioningScriptSpec(com.evolveum.midpoint.test.ProvisioningScriptSpec) ProvisioningScriptType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType) Test(org.testng.annotations.Test)

Aggregations

ExecuteProvisioningScriptOperation (com.evolveum.midpoint.provisioning.ucf.api.ExecuteProvisioningScriptOperation)2 ConnectorInstance (com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance)1 ExecuteScriptArgument (com.evolveum.midpoint.provisioning.ucf.api.ExecuteScriptArgument)1 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 StateReporter (com.evolveum.midpoint.task.api.StateReporter)1 Task (com.evolveum.midpoint.task.api.Task)1 ProvisioningScriptSpec (com.evolveum.midpoint.test.ProvisioningScriptSpec)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 OperationProvisioningScriptsType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationProvisioningScriptsType)1 ProvisioningScriptArgumentType (com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptArgumentType)1 ProvisioningScriptType (com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 Test (org.testng.annotations.Test)1