Skip to content

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

Open

Description

@zhuhaolin162

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;
}

Activity

  1. 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.[/+] on Apr 17, 2019
  2. 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.[/+] on Apr 17, 2019
  3. renner commented on Apr 17, 2019

    @renner
    Member

    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?

  4. zhuhaolin162 commented on Apr 18, 2019

    @zhuhaolin162
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions