A lightweight JavaScript SDK for testing cloud network connectivity with Oracle Cloud Infrastructure (OCI).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AppCloud Network SDK Tester</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
#output { margin-top: 20px; padding: 10px; border: 1px solid #ccc; }
button { padding: 10px 20px; margin: 5px; }
</style>
</head>
<body>
<h1>AppCloud Network SDK Tester</h1>
<p>Test cloud network connectivity and resource availability using the AppCloud SDK.</p>
<button onclick="checkNetworkStatus()">Check Network Status</button>
<button onclick="testLatency()">Test Latency</button>
<button onclick="checkResourceAvailability()">Check Resource Availability</button>
<div id="output">Results will appear here...</div>
<script>
// AppCloud Network SDK
const AppCloudNetworkSDK = {
// Configuration (replace with your OCI API endpoint and credentials)
config: {
apiEndpoint: 'https://api.example-oci-region.oraclecloud.com', // Replace with actual OCI region endpoint
tenancyId: 'ocid1.tenancy.oc1..example', // Replace with your tenancy OCID
authToken: 'your-auth-token', // Replace with your OCI API token
timeout: 5000 // Timeout in milliseconds
},
// Initialize SDK
init(config = {}) {
this.config = { ...this.config, ...config };
console.log('AppCloud Network SDK initialized');
},
// Helper: Make API request
async makeRequest(path, method = 'GET', body = null) {
try {
const headers = {
'Authorization': `Bearer ${this.config.authToken}`,
'Content-Type': 'application/json'
};
const options = { method, headers, timeout: this.config.timeout };
if (body) options.body = JSON.stringify(body);
const response = await fetch(`${this.config.apiEndpoint}${path}`, options);
if (!response.ok) throw new Error(`HTTP error: ${response.status}`);
return await response.json();
} catch (error) {
console.error('API request failed:', error);
throw error;
}
},
// Check network status
async checkNetworkStatus() {
try {
const data = await this.makeRequest('/network/v1/status');
return {
status: 'success',
message: 'Network is operational',
details: data
};
} catch (error) {
return {
status: 'error',
message: 'Network status check failed',
error: error.message
};
}
},
// Test latency to OCI endpoint
async testLatency() {
try {
const startTime = performance.now();
await this.makeRequest('/network/v1/ping');
const endTime = performance.now();
const latency = (endTime - startTime).toFixed(2);
return {
status: 'success',
message: `Latency test completed`,
latency: `${latency} ms`
};
} catch (error) {
return {
status: 'error',
message: 'Latency test failed',
error: error.message
};
}
},
// Check resource availability
async checkResourceAvailability() {
try {
const data = await this.makeRequest('/compute/v1/availability');
return {
status: 'success',
message: 'Resource availability retrieved',
details: data
};
} catch (error) {
return {
status: 'error',
message: 'Resource availability check failed',
error: error.message
};
}
}
};
// Initialize SDK
AppCloudNetworkSDK.init();
// UI interaction functions
async function checkNetworkStatus() {
const output = document.getElementById('output');
output.innerHTML = 'Checking network status...';
const result = await AppCloudNetworkSDK.checkNetworkStatus();
output.innerHTML = JSON.stringify(result, null, 2);
}
async function testLatency() {
const output = document.getElementById('output');
output.innerHTML = 'Testing latency...';
const result = await AppCloudNetworkSDK.testLatency();
output.innerHTML = JSON.stringify(result, null, 2);
}
async function checkResourceAvailability() {
const output = document.getElementById('output');
output.innerHTML = 'Checking resource availability...';
const result = await AppCloudNetworkSDK.checkResourceAvailability();
output.innerHTML = JSON.stringify(result, null, 2);
}
</script>
</body>
</html>