Skip to content

Commit

Permalink
Revert "Merge branch 'admd-module-name-information'"
Browse files Browse the repository at this point in the history
This reverts commit f158168, reversing
changes made to aa3ed6c.
  • Loading branch information
renner committed Mar 28, 2017
1 parent 22127c4 commit 38d6f31
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 182 deletions.
82 changes: 0 additions & 82 deletions src/main/java/com/suse/salt/netapi/calls/AbstractCall.java

This file was deleted.

58 changes: 29 additions & 29 deletions src/main/java/com/suse/salt/netapi/calls/LocalCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,82 +38,82 @@
*
* @param <R> the return type of the called function
*/
public class LocalCall<R> extends AbstractCall<R> {
public class LocalCall<R> implements Call<R> {

private final String functionName;
private final Optional<List<?>> arg;
private final Optional<Map<String, ?>> kwarg;
private final TypeToken<R> returnType;
private final Optional<?> metadata;
private final Optional<Integer> timeout;
private final Optional<Integer> gatherJobTimeout;

public LocalCall(String functionName, Optional<List<?>> arg,
Optional<Map<String, ?>> kwargs, TypeToken<R> returnType,
Optional<Map<String, ?>> kwarg, TypeToken<R> returnType,
Optional<?> metadata, Optional<Integer> timeout,
Optional<Integer> gatherJobTimeout) {
super(functionName, kwargs, returnType);
this.arg = arg;
this.metadata = metadata;
this.timeout = timeout;
this.gatherJobTimeout = gatherJobTimeout;
}

public LocalCall(String moduleName, String functionName, Optional<List<?>> arg,
Optional<Map<String, ?>> kwargs, TypeToken<R> returnType,
Optional<?> metadata, Optional<Integer> timeout,
Optional<Integer> gatherJobTimeout) {
super(moduleName, functionName, kwargs, returnType);
this.functionName = functionName;
this.arg = arg;
this.kwarg = kwarg;
this.returnType = returnType;
this.metadata = metadata;
this.timeout = timeout;
this.gatherJobTimeout = gatherJobTimeout;
}

public LocalCall(String functionName, Optional<List<?>> arg,
Optional<Map<String, ?>> kwargs, TypeToken<R> returnType,
Optional<Map<String, ?>> kwarg, TypeToken<R> returnType,
Optional<Integer> timeout, Optional<Integer> gatherJobTimeout) {
this(functionName, arg, kwargs, returnType, Optional.empty(),
this(functionName, arg, kwarg, returnType, Optional.empty(),
timeout, gatherJobTimeout);
}

public LocalCall(String functionName, Optional<List<?>> arg,
Optional<Map<String, ?>> kwargs, TypeToken<R> returnType,
Optional<Map<String, ?>> kwarg, TypeToken<R> returnType,
Optional<?> metadata) {
this(functionName, arg, kwargs, returnType, metadata, Optional.empty(),
this(functionName, arg, kwarg, returnType, metadata, Optional.empty(),
Optional.empty());
}

public LocalCall(String functionName, Optional<List<?>> arg,
Optional<Map<String, ?>> kwargs, TypeToken<R> returnType) {
this(functionName, arg, kwargs, returnType, Optional.empty());
Optional<Map<String, ?>> kwarg, TypeToken<R> returnType) {
this(functionName, arg, kwarg, returnType, Optional.empty());
}

public LocalCall<R> withMetadata(Object metadata) {
return new LocalCall<>(getFunctionName(), arg, getKwargs(), getReturnType(),
Optional.of(metadata), timeout, gatherJobTimeout);
return new LocalCall<>(functionName, arg, kwarg, returnType, Optional.of(metadata),
timeout, gatherJobTimeout);
}

public LocalCall<R> withoutMetadata() {
return new LocalCall<>(getFunctionName(), arg, getKwargs(), getReturnType(),
Optional.empty(), timeout, gatherJobTimeout);
return new LocalCall<>(functionName, arg, kwarg, returnType, Optional.empty(),
timeout, gatherJobTimeout);
}

public LocalCall<R> withTimeouts(Optional<Integer> timeout,
Optional<Integer> gatherJobTimeout) {
return new LocalCall<>(getFunctionName(), arg, getKwargs(), getReturnType(),
metadata, timeout, gatherJobTimeout);
return new LocalCall<>(functionName, arg, kwarg, returnType, metadata,
timeout, gatherJobTimeout);
}

public LocalCall<R> withoutTimeouts() {
return new LocalCall<>(getFunctionName(), arg, getKwargs(), getReturnType(),
metadata, Optional.empty(), Optional.empty());
return new LocalCall<>(functionName, arg, kwarg, returnType, metadata,
Optional.empty(), Optional.empty());
}

public TypeToken<R> getReturnType() {
return returnType;
}

/**
* {@inheritDoc}
*/
@Override
public Map<String, Object> getPayload() {
Map<String, Object> payload = super.getPayload();
HashMap<String, Object> payload = new HashMap<>();
payload.put("fun", functionName);
arg.ifPresent(arg -> payload.put("arg", arg));
kwarg.ifPresent(kwarg -> payload.put("kwarg", kwarg));
metadata.ifPresent(m -> payload.put("metadata", m));
timeout.ifPresent(timeout -> payload.put("timeout", timeout));
gatherJobTimeout.ifPresent(gatherJobTimeout -> payload.put("gather_job_timeout",
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/com/suse/salt/netapi/calls/RunnerCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,35 @@
*
* @param <R> the return type of the called function
*/
public class RunnerCall<R> extends AbstractCall<R> {
public class RunnerCall<R> implements Call<R> {

private final String functionName;
private final Optional<Map<String, ?>> kwargs;
private final TypeToken<R> returnType;

public RunnerCall(String functionName, Optional<Map<String, ?>> kwargs,
TypeToken<R> returnType) {
super(functionName, kwargs, returnType);
this.functionName = functionName;
this.kwargs = kwargs;
this.returnType = returnType;
}

public TypeToken<R> getReturnType() {
return returnType;
}

public RunnerCall(String moduleName, String functionName,
Optional<Map<String, ?>> kwargs, TypeToken<R> returnType) {
super(moduleName, functionName, kwargs, returnType);
/**
* {@inheritDoc}
*/
@Override
public Map<String, Object> getPayload() {
HashMap<String, Object> payload = new HashMap<>();
payload.put("fun", functionName);
kwargs.ifPresent(kwargs -> payload.put("kwargs", kwargs));
return payload;
}

/**
/**
* Calls a runner module function on the master asynchronously and
* returns information about the scheduled job that can be used to query the result.
* Authentication is done with the token therefore you have to login prior
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/com/suse/salt/netapi/calls/WheelCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@
*
* @param <R> the return type of the called function
*/
public class WheelCall<R> extends AbstractCall<R> {
public class WheelCall<R> implements Call<R> {

private final String functionName;
private final Optional<Map<String, ?>> kwargs;
private final TypeToken<R> returnType;

public WheelCall(String functionName, Optional<Map<String, ?>> kwargs,
TypeToken<R> returnType) {
super(functionName, kwargs, returnType);
TypeToken<R> returnType) {
this.functionName = functionName;
this.kwargs = kwargs;
this.returnType = returnType;
}

public WheelCall(String moduleName, String functionName,
Optional<Map<String, ?>> kwargs, TypeToken<R> returnType) {
super(moduleName, functionName, kwargs, returnType);
public TypeToken<R> getReturnType() {
return returnType;
}

/**
Expand All @@ -38,8 +43,8 @@ public WheelCall(String moduleName, String functionName,
@Override
public Map<String, Object> getPayload() {
HashMap<String, Object> payload = new HashMap<>();
payload.put("fun", getFunctionName());
getKwargs().ifPresent(payload::putAll);
payload.put("fun", functionName);
kwargs.ifPresent(payload::putAll);
return payload;
}

Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/suse/salt/netapi/utils/ClientUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,4 @@ public static ParameterizedType parameterizedType(Type ownerType, Type rawType,
Type... typeArguments) {
return newParameterizedTypeWithOwner(ownerType, rawType, typeArguments);
}

/**
* Get the name from function name e.g in case of 'state.high', this function will
* return 'state'.
* @param functionName
* @return module name
* @throws IllegalArgumentException
*/
public static String getModuleNameFromFunction(final String functionName)
throws IllegalArgumentException {
if (!functionName.contains(".")) {
throw new IllegalArgumentException(functionName);
}
return functionName.split("\\.")[0];
}
}
29 changes: 0 additions & 29 deletions src/test/java/com/suse/salt/netapi/calls/LocalCallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.google.gson.reflect.TypeToken;
import com.suse.salt.netapi.AuthModule;
import com.suse.salt.netapi.calls.modules.Cmd;
import com.suse.salt.netapi.client.SaltClient;
Expand All @@ -30,7 +29,6 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.net.HttpURLConnection;
import java.net.URI;
Expand Down Expand Up @@ -62,9 +60,6 @@ public class LocalCallTest {

private SaltClient client;

@Rule
public ExpectedException exception = ExpectedException.none();

@Before
public void init() {
URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
Expand Down Expand Up @@ -111,33 +106,9 @@ public void testWithTimeouts() {
assertEquals(runWithTimeouts.getPayload().get("gather_job_timeout"), 1);
}

/**
* Verify that system return the correct module name
*/

@Test
public void testModuleName() {
LocalCall<String> run = Cmd.run("echo 'hello world'");
assertEquals(run.getModuleName(), "cmd");

}

/**
* Verify that system throw IllegalArgumentException when function name is not in right
* format.
*/
@Test
public void testFunctionName() {
exception.expect(IllegalArgumentException.class);
LocalCall<String> run = new LocalCall<>("cmdrun", Optional.empty(),
Optional.empty(), new TypeToken<String>(){});
System.out.println(run.getModuleName());
}

/**
* Verify correctness of the request body with an exemplary synchronous call.
*/

@Test
public void testCallSync() throws SaltException {
stubFor(any(urlMatching("/run"))
Expand Down
13 changes: 0 additions & 13 deletions src/test/java/com/suse/salt/netapi/utils/ClientUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,4 @@ public void testStreamToString() {
assertEquals("Result doesn't match test string", TEST_STRING, result);
}

@Test
public void testGetModuleNameFromRightFunction() {
final String TEST_STRING = "state.high";
String result = ClientUtils.getModuleNameFromFunction(TEST_STRING);
assertEquals("Result doesn't match test string", result, "state");
}

@Test(expected = IllegalArgumentException.class)
public void testGetModuleNameFromWrongFunction() {
final String TEST_STRING = "statehigh";
ClientUtils.getModuleNameFromFunction(TEST_STRING);
}

}

0 comments on commit 38d6f31

Please sign in to comment.