/* * generate query container state request */ static int generate_query_container_state_request( char** buffer, int* size, hadoop_rpc_proxy_t* proxy, int container_id) { int rc; struct pbc_wmessage* req = pbc_wmessage_new(env, "GetContainerStatusRequestProto"); if (!req) { opal_output(0, "get GetContainerStatusRequestProto message failed.\n"); return -1; } // set container_id struct pbc_wmessage* id_proto = pbc_wmessage_message(req, "container_id"); if (!id_proto) { opal_output(0, "get ContainerIdProto from ContainerLaunchContextProto failed.\n"); pbc_wmessage_delete(req); return -1; } rc = pbc_wmessage_integer(id_proto, "id", container_id, NULL); if (0 != rc) { opal_output(0, "pack container-id failed.\n"); pbc_wmessage_delete(req); return -1; } rc = set_app_attempt_id(id_proto, "app_attempt_id", proxy); if (0 != rc) { opal_output(0, "pack app_attempt_id failed.\n"); pbc_wmessage_delete(req); return -1; } rc = set_app_id(id_proto, "app_id", proxy); if (0 != rc) { opal_output(0, "pack app_id failed.\n"); pbc_wmessage_delete(req); return -1; } struct pbc_slice slice; pbc_wmessage_buffer(req, &slice); /* try to create HadoopRpcRequestProto */ rc = generate_hadoop_request((const char*)(slice.buffer), slice.len, CONTAINER_MANAGER_PROTOCOL_NAME, GET_CONTAINER_STATUS_METHOD_NAME, buffer, size); if (0 != rc) { opal_output(0, "create HadoopRpcRequestProto failed.\n"); pbc_wmessage_delete(req); return -1; } pbc_wmessage_delete(req); return 0; }
static void set_app_id(LPWSTR app_id) { HMODULE shell32; HRESULT (*set_app_id)(LPWSTR app_id); shell32 = LoadLibrary(L"shell32.dll"); if (!shell32) return; set_app_id = (void *) GetProcAddress(shell32, "SetCurrentProcessExplicitAppUserModelID"); if (!set_app_id) return; if (!SUCCEEDED(set_app_id(app_id))) print_error(L"warning: could not set app ID", GetLastError()); }
static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep, LPWSTR *prefix_args, int *prefix_args_len, int *is_git_command, LPWSTR *working_directory, int *full_path, int *skip_arguments, int *allocate_console, int *show_console, int *append_quote_to_cmdline) { int i, id, minimal_search_path, needs_a_console, no_hide, wargc; int append_quote; LPWSTR *wargv; WCHAR *app_id; #define BUFSIZE 65536 static WCHAR buf[BUFSIZE]; LPWSTR buf2 = buf; int len; for (id = 0; ; id++) { minimal_search_path = 0; needs_a_console = 0; no_hide = 0; append_quote = 0; app_id = NULL; len = LoadString(NULL, id, buf, BUFSIZE); if (!len) { if (!id) return 0; /* no resources found */ fwprintf(stderr, L"Need a valid command-line; " L"Edit the string resources accordingly\n"); exit(1); } if (len >= BUFSIZE) { fwprintf(stderr, L"Could not read resource (too large)\n"); exit(1); } for (;;) { if (strip_prefix(buf, &len, L"MINIMAL_PATH=1 ")) minimal_search_path = 1; else if (strip_prefix(buf, &len, L"ALLOC_CONSOLE=1 ")) needs_a_console = 1; else if (strip_prefix(buf, &len, L"SHOW_CONSOLE=1 ")) no_hide = 1; else if (strip_prefix(buf, &len, L"APPEND_QUOTE=1 ")) append_quote = 1; else if (strip_prefix(buf, &len, L"APP_ID=")) { LPWSTR space = wcschr(buf, L' '); size_t app_id_len = space - buf; if (!space) { len -= 7; memmove(buf, buf + 7, len * sizeof(WCHAR)); break; } app_id = wcsdup(buf); app_id[app_id_len] = L'\0'; len -= app_id_len + 1; memmove(buf, buf + app_id_len + 1, len * sizeof(WCHAR)); } else break; } buf[len] = L'\0'; if (!id) SetEnvironmentVariable(L"EXEPATH", exepath); buf2 = expand_variables(buf, BUFSIZE); extract_first_arg(buf2, exepath, exep); if (_waccess(exep, 0) != -1) break; fwprintf(stderr, L"Skipping command-line '%s'\n('%s' not found)\n", buf2, exep); if (app_id) free(app_id); } *prefix_args = buf2; *prefix_args_len = wcslen(buf2); *is_git_command = 0; wargv = CommandLineToArgvW(GetCommandLine(), &wargc); for (i = 1; i < wargc; i++) { if (!wcscmp(L"--no-cd", wargv[i])) *working_directory = NULL; else if (!wcscmp(L"--cd-to-home", wargv[i])) *working_directory = (LPWSTR) 1; else if (!wcsncmp(L"--cd=", wargv[i], 5)) *working_directory = wcsdup(wargv[i] + 5); else if (!wcscmp(L"--minimal-search-path", wargv[i])) minimal_search_path = 1; else if (!wcscmp(L"--no-minimal-search-path", wargv[i])) minimal_search_path = 0; else if (!wcscmp(L"--needs-console", wargv[i])) needs_a_console = 1; else if (!wcscmp(L"--no-needs-console", wargv[i])) needs_a_console = 0; else if (!wcscmp(L"--hide", wargv[i])) no_hide = 0; else if (!wcscmp(L"--no-hide", wargv[i])) no_hide = 1; else if (!wcscmp(L"--append-quote", wargv[i])) append_quote = 1; else if (!wcscmp(L"--no-append-quote", wargv[i])) append_quote = -1; else if (!wcsncmp(L"--command=", wargv[i], 10)) { LPWSTR expanded; wargv[i] += 10; expanded = expand_variables(wargv[i], wcslen(wargv[i])); if (expanded == wargv[i]) expanded = wcsdup(expanded); extract_first_arg(expanded, exepath, exep); *prefix_args = expanded; *prefix_args_len = wcslen(*prefix_args); *skip_arguments = i; break; } else if (!wcsncmp(L"--app-id=", wargv[i], 9)) { free(app_id); app_id = wcsdup(wargv[i] + 9); } else break; *skip_arguments = i; } if (minimal_search_path) *full_path = 0; if (needs_a_console) *allocate_console = 1; if (no_hide) *show_console = 1; if (append_quote) *append_quote_to_cmdline = append_quote == 1; if (app_id) set_app_id(app_id); LocalFree(wargv); return 1; }
/** * generate launch container PB request message ContainerLaunchContextProto { optional ContainerIdProto container_id = 1; optional string user = 2; optional ResourceProto resource = 3; repeated StringLocalResourceMapProto localResources = 4; optional bytes container_tokens = 5; repeated StringBytesMapProto service_data = 6; repeated StringStringMapProto environment = 7; repeated string command = 8; repeated ApplicationACLMapProto application_ACLs = 9; } message StartContainerRequestProto { optional ContainerLaunchContextProto container_launch_context = 1; } */ static int generate_launch_container_request( char** buffer, int* size, hadoop_rpc_proxy_t* proxy, int container_id, containers_launch_context_t* launch_context) { int rc; struct pbc_wmessage* req = pbc_wmessage_new(env, "StartContainerRequestProto"); if (!req) { opal_output(0, "get StartContainerRequestProto message failed.\n"); return -1; } struct pbc_wmessage* ctx = pbc_wmessage_message(req, "container_launch_context"); if (!ctx) { opal_output(0, "get container_launch_context from StartContainerRequestProto failed.\n"); pbc_wmessage_delete(req); return -1; } // set container_id struct pbc_wmessage* id_proto = pbc_wmessage_message(ctx, "container_id"); if (!id_proto) { opal_output(0, "get ContainerIdProto from ContainerLaunchContextProto failed.\n"); pbc_wmessage_delete(req); return -1; } rc = pbc_wmessage_integer(id_proto, "id", container_id, NULL); if (0 != rc) { opal_output(0, "pack container-id failed.\n"); pbc_wmessage_delete(req); return -1; } rc = set_app_attempt_id(id_proto, "app_attempt_id", proxy); if (0 != rc) { opal_output(0, "pack app_attempt_id failed.\n"); pbc_wmessage_delete(req); return -1; } rc = set_app_id(id_proto, "app_id", proxy); if (0 != rc) { opal_output(0, "pack app_id failed.\n"); pbc_wmessage_delete(req); return -1; } // pack user rc = pbc_wmessage_string(ctx, "user", getlogin(), 0); if (rc != 0) { opal_output(0, "pack user name failed.\n"); return -1; } // pack resource struct pbc_wmessage* res_msg = pbc_wmessage_message(ctx, "resource"); if (!res_msg) { opal_output(0, "get resource_proto from context failed.\n"); return -1; } rc = pbc_wmessage_integer(res_msg, "memory", launch_context->resource.memory_per_slot, NULL); if (rc != 0) { pbc_wmessage_delete(req); opal_output(0, "pack memory to resource failed.\n"); return -1; } // TODO, in 2.0.3, need pack cpu // pack localResources rc = set_local_resources(ctx, "localResources"); if (rc != 0) { pbc_wmessage_delete(req); opal_output(0, "pack local resources failed.\n"); return -1; } // pack env int offset = 0; if (launch_context->env) { while (launch_context->env[offset]) { struct pbc_wmessage* env_msg = pbc_wmessage_message(ctx, "environment"); if (!env_msg) { pbc_wmessage_delete(req); opal_output(0, "get env message from context failed.\n"); return -1; } char* key = get_env_key(launch_context->env[offset]); char* val = get_env_val(launch_context->env[offset]); if ((!key) || (!val)) { if (key) { free(key); } if (val) { free(val); } pbc_wmessage_delete(req); opal_output(0, "get env key or value failed, env=%s.\n", launch_context->env[offset]); return -1; } // pack key rc = pbc_wmessage_string(env_msg, "key", key, 0); free(key); if (rc != 0) { free(val); pbc_wmessage_delete(req); opal_output(0, "set key to environment failed.\n"); return -1; } // pack val rc = pbc_wmessage_string(env_msg, "value", val, 0); if (rc != 0) { free(val); pbc_wmessage_delete(req); opal_output(0, "set value to environment failed.\n"); return -1; } free(val); offset++; } } // pack $PATH, $LD_LIBRARY_PATH, $DYLD_LIBRARY_PATH, $CLASSPATH to env if (0 != (rc = pack_env_to_launch_ctx("PATH", ctx))) { pbc_wmessage_delete(req); return -1; } if (0 != (rc = pack_env_to_launch_ctx("LD_LIBRARY_PATH", ctx))) { pbc_wmessage_delete(req); return -1; } if (0 != (rc = pack_env_to_launch_ctx("DYLD_LIBRARY_PATH", ctx))) { pbc_wmessage_delete(req); return -1; } if (0 != (rc = pack_env_to_launch_ctx("CLASSPATH", ctx))) { pbc_wmessage_delete(req); return -1; } // pack command char* command = concat_argv_to_cmd(launch_context->argv); if (!command) { pbc_wmessage_delete(req); opal_output(0, "concat argv to command to command failed. argv[0]:%s.\n", launch_context->argv[0]); return -1; } rc = pbc_wmessage_string(ctx, "command", command, 0); free(command); if (rc != 0) { opal_output(0, "pack command to context failed.\n"); pbc_wmessage_delete(req); return -1; } struct pbc_slice slice; pbc_wmessage_buffer(req, &slice); /* try to create HadoopRpcRequestProto */ rc = generate_hadoop_request((const char*)(slice.buffer), slice.len, CONTAINER_MANAGER_PROTOCOL_NAME, START_CONTAINER_METHOD_NAME, buffer, size); if (0 != rc) { opal_output(0, "create HadoopRpcRequestProto failed.\n"); pbc_wmessage_delete(req); return -1; } pbc_wmessage_delete(req); return 0; }