Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the asynchronous run method, the test found that the actual task was less than the original task. #272

Open
zhuhaolin162 opened this issue Apr 17, 2019 · 2 comments

Comments

@zhuhaolin162
Copy link

SaltClient.class

By using the following asynchronous run method, saltstack has fewer actual tasks than it does in concurrent situations, What should I do? Are there any configurations that are not configured correctly?

public CompletionStage<Map<String, Object>> run(String username, String password, AuthModule eauth, String client, Target target, String function, List args, Map<String, Object> kwargs) {
Map<String, Object> props = new HashMap();
props.put("username", username);
props.put("password", password);
props.put("eauth", eauth.getValue());
props.put("client", client);
props.putAll(target.getProps());
props.put("fun", function);
props.put("arg", args);
props.put("kwarg", kwargs);
List<Map<String, Object>> list = Collections.singletonList(props);
String payload = this.gson.toJson(list);
CompletionStage<Map<String, Object>> result = this.asyncHttpClient.post(this.uri.resolve("run"), payload, JsonParser.RUN_RESULTS).thenApply((s) -> {
return (Map)((List)s.getResult()).get(0);
});
return result;
}

@zhuhaolin162 zhuhaolin162 changed the title Using the asynchronous run method, the test found that there were fewer actual tasks than real tasks. Using the asynchronous running method, the test found that the actual task was less than the original task. Apr 17, 2019
@zhuhaolin162 zhuhaolin162 changed the title Using the asynchronous running method, the test found that the actual task was less than the original task. Using the asynchronous run method, the test found that the actual task was less than the original task. Apr 17, 2019
@renner
Copy link
Member

renner commented Apr 17, 2019

Hey @zhuhaolin162, what exactly do you mean when you say "saltstack has fewer actual tasks than it does in concurrent situations"? How exactly do you use this method and what is the unexpected outcome vs. the expected?

@zhuhaolin162
Copy link
Author

zhuhaolin162 commented Apr 18, 2019

Test purpose :
I want to generate 100 files in /tmp/test , but in fact it just generate 75 files(the nums is not exactly every times)

Test result:
[root@rhel72 test]# pwd
/tmp/test
[root@rhel72 test]# ls -l |grep '^-'|wc -l
75

Test code:
public static String ayscExecute(String ip, final String command) {
try {
CloseableHttpAsyncClient httpClient = HttpClientUtils.defaultClient();
SaltClient client = new SaltClient(URI.create(ConstUtils.SALT_API_URL), new HttpAsyncClientImpl(httpClient));
IPCidr target = new IPCidr(ip);
List list = new ArrayList();
list.add(command);
Runnable cleanup = () -> {
try {
httpClient.close();
} catch (Exception e) {
logger.error("close error",e);
}
};
CompletionStage<Map<String, Object>> result = client.run(ConstUtils.SALT_API_USER,
ConstUtils.SALT_API_PASSWORD, AuthModule.PAM,"local",
target,"cmd.run",list,new LinkedHashMap<>());
result
.thenAccept(t-> System.out.println(t))
.thenRun(cleanup);
}catch (Exception e){
logger.error("aysc exec failed",e);
return "fail";
}
return "ok";
}

public static void main(String[] args) {
ConstUtils.SALT_API_USER = "user";
ConstUtils.SALT_API_PASSWORD = "password";
ConstUtils.SALT_API_URL = "http://192.168.6.138:8000";
String ip = "192.168.6.138";
ExecutorService executorService = Executors.newFixedThreadPool(1);
AtomicInteger count = new AtomicInteger();
executorService.submit(()->{
for(int i=0;i<100;i++) {
int num = count.getAndIncrement();
String command = String.format("touch /tmp/test/%s;echo %s",num,num);
System.out.println(command);
String result = SaltUtil.ayscExecute(ip,command);
System.out.println(result);
}
});
}

Thank you for you help! @renner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants