Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Apr 27, 2023
2 parents 0adf80a + 69eeff6 commit 5142841
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected List<ProgressBar> load() {
return Collections.singletonList(new ProgressBar(100, ProgressBar.State.SUCCESS,
new SingleLocalizableMessage(KEY_ADDED, new Object[] { size }, KEY_ADDED)));
case DELETE:
return Collections.singletonList(new ProgressBar(100, ProgressBar.State.DANGER));
return Collections.singletonList(new ProgressBar(0, ProgressBar.State.SECONDARY));
default:
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ public <T extends ObjectType> PrismObject<T> getObject(
//noinspection unchecked
object = (PrismObject<T>) objectResolver
.getObject(clazz, oid, parsedOptions.getCollection(), task, result)
.asPrismObject()
.cloneIfImmutable();
.asPrismObject();

object = schemaTransformer.applySchemasAndSecurityToObject(object, parsedOptions, task, result);
executeResolveOptions(object.asObjectable(), parsedOptions, task, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.List;
import java.util.Set;

import com.evolveum.midpoint.util.exception.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
Expand All @@ -30,11 +32,12 @@
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.ExtensionValueGenerator;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import static com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection;

/**
* Originally, this class checks number of selected infra operations needed to execute "object add" operation.
*
Expand Down Expand Up @@ -64,7 +67,7 @@ public class TestOperationPerf extends AbstractStoryTest {
private static final String GENERATED_EMPTY_ROLE_OID_FORMAT = "00000000-0000-ffff-2000-e0000000%04d";
private static final String GENERATED_EMPTY_ROLE_NAME_FORMAT = "Empty Role %04d";

private static final int GET_ITERATIONS = 1_000;
private static final int GET_ITERATIONS = 2_000_000;

private final ExtensionValueGenerator extensionValueGenerator = ExtensionValueGenerator.withDefaults();

Expand Down Expand Up @@ -118,18 +121,27 @@ public void test000Sanity() throws Exception {
displayValue("Object compares", InternalMonitor.getCount(InternalCounters.PRISM_OBJECT_COMPARE_COUNT));
}

/** "Basic user" - 10 extension properties, 3 assignments. */
/**
* - `alice` is "basic user" - 10 extension properties, 3 assignments.
* - `bob` is "heavy user" - "Heavy user" - 50 properties, 40 assignments.
* */
@Test
public void test100AddAlice() throws Exception {
public void test100AddAndGet() throws Exception {
when("creating users");
testAddUser(USER_ALICE_FILE, USER_ALICE_OID, 10, 3);
testGetUser(USER_ALICE_OID);
}

/** "Heavy user" - 50 properties, 40 assignments. */
@Test
public void test110AddBob() throws Exception {
testAddUser(USER_BOB_FILE, USER_BOB_OID, 50, 40);
testGetUser(USER_BOB_OID);

and("getting users");
testGetUser("alice", USER_ALICE_OID);
testGetUser("bob", USER_BOB_OID);
testGetUser("alice", USER_ALICE_OID);
testGetUser("bob", USER_BOB_OID);
testGetUser("alice", USER_ALICE_OID);
testGetUser("bob", USER_BOB_OID);
testGetUser("alice", USER_ALICE_OID);
testGetUser("bob", USER_BOB_OID);
testGetUser("alice", USER_ALICE_OID);
testGetUser("bob", USER_BOB_OID);
}

private void testAddUser(File userFile, String userOid, int extProperties, int roles) throws Exception {
Expand Down Expand Up @@ -190,18 +202,25 @@ private void setRandomOrganizations(PrismObject<UserType> userBefore, int number
}

/** MID-8479 */
private void testGetUser(String oid) throws CommonException {
Task task = getTestTask();
OperationResult result = task.getResult();
private void testGetUser(String name, String oid) throws CommonException {
executeGetUserIterations(oid, GET_ITERATIONS / 10); // heating up

long start = System.currentTimeMillis();
for (int i = 0; i < GET_ITERATIONS; i++) {
modelService.getObject(UserType.class, oid, null, task, result);
}
executeGetUserIterations(oid, GET_ITERATIONS);
long duration = System.currentTimeMillis() - start;

display(String.format("Retrieved a user in %.3f ms", (double) duration / GET_ITERATIONS));
display(String.format("Retrieved %s in %,.3f µs", name, 1000.0 * duration / GET_ITERATIONS));
}

assertSuccess(result);
private void executeGetUserIterations(String oid, int iterations) throws CommonException {
var task = getTestTask();
var options = createReadOnlyCollection();
OperationResult result1 = null;
for (int i = 0; i < iterations; i++) {
if (i % 100 == 0) {
result1 = new OperationResult("dummy"); // to avoid operation result aggregation
}
modelService.getObject(UserType.class, oid, options, task, result1);
}
}
}
4 changes: 0 additions & 4 deletions tools/ninja/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand Down
14 changes: 2 additions & 12 deletions tools/ninja/src/main/java/com/evolveum/midpoint/ninja/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.evolveum.midpoint.ninja.impl.Command;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.BaseOptions;
import com.evolveum.midpoint.ninja.opts.ConnectionOptions;
import com.evolveum.midpoint.ninja.util.NinjaUtils;

public class Main {
Expand Down Expand Up @@ -71,19 +70,10 @@ protected <T> void run(String[] args) {

NinjaContext context = null;
try {
ConnectionOptions connection = Objects.requireNonNull(
NinjaUtils.getOptions(jc, ConnectionOptions.class));
Action<T> action;
if (connection.isUseWebservice()) {
action = Command.createRestAction(parsedCommand);
} else {
action = Command.createRepositoryAction(parsedCommand);
}
Action<T> action = Command.createRepositoryAction(parsedCommand);

if (action == null) {
String strConnection = connection.isUseWebservice() ? "webservice" : "repository";
System.err.println("Action for command '" + parsedCommand + "' not found (connection: '"
+ strConnection + "')");
System.err.println("Action for command '" + parsedCommand + "' not found");
return;
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
*/
public enum Command {

IMPORT("import", ImportOptions.class, ImportRepositoryAction.class, null),
IMPORT("import", ImportOptions.class, ImportRepositoryAction.class),

EXPORT("export", ExportOptions.class, ExportRepositoryAction.class, null),
EXPORT("export", ExportOptions.class, ExportRepositoryAction.class),

DELETE("delete", DeleteOptions.class, DeleteRepositoryAction.class, null),
DELETE("delete", DeleteOptions.class, DeleteRepositoryAction.class),

COUNT("count", CountOptions.class, CountRepositoryAction.class, null),
COUNT("count", CountOptions.class, CountRepositoryAction.class),

VERIFY("verify", VerifyOptions.class, VerifyRepositoryAction.class, null),
VERIFY("verify", VerifyOptions.class, VerifyRepositoryAction.class),

KEYS("keys", ListKeysOptions.class, ListKeysRepositoryAction.class, null),
KEYS("keys", ListKeysOptions.class, ListKeysRepositoryAction.class),

INFO("info", InfoOptions.class, InfoRepositoryAction.class, null),
INFO("info", InfoOptions.class, InfoRepositoryAction.class),

IMPORT_AUDIT("importAudit", ImportAuditOptions.class, ImportAuditRepositoryAction.class, null),
IMPORT_AUDIT("importAudit", ImportAuditOptions.class, ImportAuditRepositoryAction.class),

EXPORT_AUDIT("exportAudit", ExportAuditOptions.class, ExportAuditRepositoryAction.class, null),
EXPORT_AUDIT("exportAudit", ExportAuditOptions.class, ExportAuditRepositoryAction.class),

TRACE("trace", EditTraceOptions.class, EditTraceAction.class, null);
TRACE("trace", EditTraceOptions.class, EditTraceAction.class);

// todo reencrypt, modify, bulk, etc

Expand All @@ -47,14 +47,10 @@ public enum Command {

private final Class<? extends RepositoryAction<?>> repositoryAction;

private final Class<? extends RestAction<?>> restAction;

<T> Command(String commandName, Class<T> options, Class<? extends RepositoryAction<T>> repositoryAction,
Class<? extends RestAction<T>> restAction) {
<T> Command(String commandName, Class<T> options, Class<? extends RepositoryAction<T>> repositoryAction) {
this.commandName = commandName;
this.options = options;
this.repositoryAction = repositoryAction;
this.restAction = restAction;
}

public String getCommandName() {
Expand Down Expand Up @@ -87,24 +83,6 @@ public static <T> RepositoryAction<T> createRepositoryAction(String command) {
}
}

public static <T> RestAction<T> createRestAction(String command) {
Command cmd = findCommand(command);
if (cmd == null) {
return null;
}

try {
if (cmd.restAction == null) {
return null;
}

//noinspection unchecked
return (RestAction<T>) cmd.restAction.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}

private static Command findCommand(String command) {
if (command == null) {
return null;
Expand Down

0 comments on commit 5142841

Please sign in to comment.