Skip to content

Commit

Permalink
Fixed list deployments dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioSanch3z committed Nov 6, 2024
1 parent 9a88c5d commit 0144643
Show file tree
Hide file tree
Showing 4 changed files with 1,544 additions and 1,537 deletions.
3 changes: 1 addition & 2 deletions apricot_magics/apricot_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def execute_command(self, cmd):
result = run(cmd, stdout=PIPE, stderr=PIPE, check=True, text=True)
return result.stdout # Return only stdout
except CalledProcessError as e:
print(f"Command failed: {e.stderr}")
return "Fail"

def create_auth_pipe(self, infrastructure_id):
Expand Down Expand Up @@ -506,7 +505,7 @@ def apricot(self, code, cell=None):
print(f"Error: {e}")
return "Failed"
finally:
self.cleanup_files('auth-pipe')
self.cleanup_files('auth-pipe', 'key.pem')

return "Done"

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyterlab/application": "^4.2.0",
"@jupyterlab/apputils": "^4.3.1",
"@jupyterlab/application": "^4.3.0",
"@jupyterlab/apputils": "^4.4.0",
"@jupyterlab/docregistry": "^4.3.0",
"@jupyterlab/notebook": "^4.2.0",
"@jupyterlab/services": "^7.3.0",
Expand Down
74 changes: 41 additions & 33 deletions src/listDeployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,23 @@ async function populateTable(table: HTMLTableElement): Promise<void> {
const stateCell = row.insertCell();

// Fetch state and IP concurrently using the merged function
const [state, ip] = await Promise.all([
fetchInfrastructureData(kernel, infrastructure, stateCell, 'state'),
fetchInfrastructureData(kernel, infrastructure, ipCell, 'ip')
]);

// Update state and IP cells
stateCell.textContent = state;
ipCell.textContent = ip;
try {
const [state, ip] = await Promise.all([
fetchInfrastructureData(kernel, infrastructure, stateCell, 'state'),
fetchInfrastructureData(kernel, infrastructure, ipCell, 'ip')
]);

// Update state and IP cells
stateCell.textContent = state;
ipCell.textContent = ip;
} catch (error) {
console.error(
`Error fetching data for infrastructure ${infrastructure.name}:`,
error
);
stateCell.textContent = 'Error';
ipCell.textContent = 'Error';
}
})
);
}
Expand All @@ -167,42 +176,41 @@ async function fetchInfrastructureData(
const cmd = await getInfrastructureInfo(infrastructure, dataType);

return new Promise<string>(resolve => {
cell.textContent = 'Loading...';
// Execute the command through the kernel
const future = kernel.requestExecute({ code: cmd });

future.onIOPub = (msg: any) => {
const content = msg.content as any;
const outputData =
content.text || (content.data && content.data['text/plain']);

// Ensure outputData is not undefined before resolving the promise
if (outputData !== undefined) {
if (outputData && outputData.trim() !== '') {
console.log(`Received output for ${dataType}:`, outputData);

let result: string;

if (dataType === 'state') {
// Extract the state from the output
const stateWords = outputData.trim().split(' ');
const stateIndex = stateWords.indexOf('state:');
result =
stateIndex !== -1 && stateIndex < stateWords.length - 1
? stateWords[stateIndex + 1].trim()
: 'Error';
// Check if the output contains "error" in the message
if (outputData.toLowerCase().includes('error')) {
result = 'Fail';
} else {
// dataType is 'ip'
// Extract the IP from the output (get the last word)
const ipWords = outputData.trim().split(' ');
const ip = ipWords[ipWords.length - 1];
result = ip ? ip : 'Error';
// Process output based on dataType if no error is present
if (dataType === 'state') {
const stateWords = outputData.trim().split(' ');
const stateIndex = stateWords.indexOf('state:');
result =
stateIndex !== -1 && stateIndex < stateWords.length - 1
? stateWords[stateIndex + 1].trim()
: 'Error';
} else {
// Extract IP from output for dataType 'ip'
const ipWords = outputData.trim().split(' ');
result = ipWords[ipWords.length - 1] || 'Error';
}
}

resolve(result);
}
};

future.done.then(() => {
// In case the onIOPub doesn't resolve the promise
resolve('Error');
});
});
}

Expand Down Expand Up @@ -258,18 +266,18 @@ async function getInfrastructureInfo(
echo -e "${authContent}" > $PWD/${pipeAuth} &
if [ "${dataType}" = "state" ]; then
stateOut=(python3 ${imClientPath} getstate ${infrastructureID} -r https://im.egi.eu/im -a PWD/${pipeAuth})
stateOut=$(python3 ${imClientPath} getstate ${infrastructureID} -r https://im.egi.eu/im -a $PWD/${pipeAuth})
else
stateOut=(python3 ${imClientPath} getvminfo ${infrastructureID} 0 net_interface.1.ip -r https://im.egi.eu/im -a PWD/${pipeAuth})
stateOut=$(python3 ${imClientPath} getvminfo ${infrastructureID} 0 net_interface.1.ip -r https://im.egi.eu/im -a $PWD/${pipeAuth})
fi
# Remove pipe
rm -f $PWD/${pipeAuth} &> /dev/null
# Print state output on stderr or stdout
if [ $? -ne 0 ]; then
>&2 echo -e stateOut
>&2 echo -e $stateOut
exit 1
else
echo -e stateOut
echo -e $stateOut
fi
`;

Expand Down
Loading

0 comments on commit 0144643

Please sign in to comment.