shwstppr commented on code in PR #9840:
URL: https://github.com/apache/cloudstack/pull/9840#discussion_r1828890915


##########
agent/src/main/java/com/cloud/agent/Agent.java:
##########
@@ -444,59 +466,87 @@ protected void cancelTasks() {
      * when host is added back
      */
     protected void cleanupAgentZoneProperties() {
-        _shell.setPersistentProperty(null, "zone", "");
-        _shell.setPersistentProperty(null, "cluster", "");
-        _shell.setPersistentProperty(null, "pod", "");
+        shell.setPersistentProperty(null, "zone", "");
+        shell.setPersistentProperty(null, "cluster", "");
+        shell.setPersistentProperty(null, "pod", "");
+    }
+
+    public void lockStartupTask(final Link link) {
+        logger.debug("Creating startup task for link: {}", getLinkLog(link));
+        StartupTask currentTask = startupTask.get();
+        if (currentTask != null) {
+            logger.warn("A Startup task is already locked or in progress, 
cannot create for link {}",
+                    getLinkLog(link));
+            return;
+        }
+        currentTask = new StartupTask(link);
+        if (startupTask.compareAndSet(null, currentTask)) {
+            selfTaskExecutor.schedule(currentTask, startupWait, 
TimeUnit.SECONDS);
+            return;
+        }
+        logger.warn("Failed to lock a StartupTask for link: {}", 
getLinkLog(link));
     }
 
-    public synchronized void lockStartupTask(final Link link) {
-        _startup = new StartupTask(link);
-        _timer.schedule(_startup, _startupWait);
+    protected boolean cancelStartupTask() {
+        StartupTask task = startupTask.getAndSet(null);
+        if (task != null) {
+            task.cancel();
+            return true;
+        }
+        return false;
     }
 
     public void sendStartup(final Link link) {
-        final StartupCommand[] startup = _resource.initialize();
+        final StartupCommand[] startup = serverResource.initialize();
         if (startup != null) {
-            final String msHostList = _shell.getPersistentProperty(null, 
"host");
+            final String msHostList = shell.getPersistentProperty(null, 
"host");
             final Command[] commands = new Command[startup.length];
             for (int i = 0; i < startup.length; i++) {
                 setupStartupCommand(startup[i]);
                 startup[i].setMSHostList(msHostList);
                 commands[i] = startup[i];
             }
-            final Request request = new Request(_id != null ? _id : -1, -1, 
commands, false, false);
+            final Request request = new Request(id != null ? id : -1, -1, 
commands, false, false);
             request.setSequence(getNextSequence());
 
             logger.debug("Sending Startup: {}", request.toString());
             lockStartupTask(link);
             try {
                 link.send(request.toBytes());
             } catch (final ClosedChannelException e) {
-                logger.warn("Unable to send request: {}", request.toString());
+                logger.warn("Unable to send request to {} due to '{}', 
request: {}",
+                        getLinkLog(link), e.getMessage(), request);
             }
 
-            if (_resource instanceof ResourceStatusUpdater) {
-                ((ResourceStatusUpdater) 
_resource).registerStatusUpdater(this);
+            if (serverResource instanceof ResourceStatusUpdater) {
+                ((ResourceStatusUpdater) 
serverResource).registerStatusUpdater(this);
             }
         }
     }
 
-    protected void setupStartupCommand(final StartupCommand startup) {
-        InetAddress addr;
+    protected String retrieveHostname() {
+        if (logger.isTraceEnabled()) {
+            logger.trace(" Retrieving hostname " + 
serverResource.getClass().getSimpleName());
+        }
+        final String result = 
Script.runSimpleBashScript(Script.getExecutableAbsolutePath("hostname"), 500);

Review Comment:
   `Script.getExecutableAbsolutePath` finds in all locations from PATH and if 
not found then it returns the string as it is. It should allow execution in 
those cases?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to