Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Here's a list of Hypernode API features implemented in the client.

- Updating one or multiple Hypernode settings at once.
- Querying/polling the logbook for the status of a job.
- Creating and cancelling Ephemeral Hypernode instances.
- Creating and cancelling Brancher Hypernode instances.
8 changes: 4 additions & 4 deletions src/HypernodeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Hypernode\Api\Exception\HypernodeApiClientException;
use Hypernode\Api\Exception\HypernodeApiServerException;
use Hypernode\Api\Service\App;
use Hypernode\Api\Service\EphemeralApp;
use Hypernode\Api\Service\BrancherApp;
use Hypernode\Api\Service\Logbook;
use Hypernode\Api\Service\Settings;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -19,15 +19,15 @@ class HypernodeClient

public HttpMethodsClientInterface $api;
public App $app;
public EphemeralApp $ephemeralApp;
public BrancherApp $brancherApp;
public Settings $settings;
public Logbook $logbook;

public function __construct(HttpMethodsClientInterface $apiClient)
{
$this->api = $apiClient;
$this->app = new App($this);
$this->ephemeralApp = new EphemeralApp($this);
$this->brancherApp = new BrancherApp($this);
$this->settings = new Settings($this);
$this->logbook = new Logbook($this);
}
Expand All @@ -46,4 +46,4 @@ public function maybeThrowApiExceptions(ResponseInterface $response)
throw new HypernodeApiClientException($response);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Service/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class App extends AbstractService
{
public const V2_APP_DETAIL_URL = "/v2/app/%s/";
public const V2_APP_CANCEL_URL = "/v2/app/%s/cancel/";
public const V2_APP_EPHEMERAL_URL = "/v2/app/%s/ephemeral/";
public const V2_APP_BRANCHER_URL = "/v2/app/%s/brancher/";
public const V1_APP_FLOWS_URL = "/logbook/v1/logbooks/%s/flows/";
}
14 changes: 7 additions & 7 deletions src/Service/EphemeralApp.php → src/Service/BrancherApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
use Hypernode\Api\Exception\HypernodeApiClientException;
use Hypernode\Api\Exception\HypernodeApiServerException;

class EphemeralApp extends AbstractService
class BrancherApp extends AbstractService
{
/**
* Create an ephemeral app for given parent app.
* Create an brancher app for given parent app.
*
* @param string $app Name of the parent app
* @return string Name of the ephemeral app
* @return string Name of the brancher app
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function create(string $app): string
{
$url = sprintf(App::V2_APP_EPHEMERAL_URL, $app);
$url = sprintf(App::V2_APP_BRANCHER_URL, $app);

$response = $this->client->api->post($url);

Expand All @@ -31,9 +31,9 @@ public function create(string $app): string
}

/**
* Cancel an ephemeral app.
* Cancel an brancher app.
*
* @param string $app Name of the ephemeral app
* @param string $app Name of the brancher app
* @return void
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
Expand All @@ -46,4 +46,4 @@ public function cancel(string $app): void

$this->client->maybeThrowApiExceptions($response);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
use Hypernode\Api\Exception\HypernodeApiServerException;
use Hypernode\Api\HypernodeClientTestCase;

class EphemeralAppTest extends HypernodeClientTestCase
class BrancherAppTest extends HypernodeClientTestCase
{
public function testCreateEphemeralApp()
public function testCreateBrancherApp()
{
$this->responses->append(
new Response(200, [], json_encode([
'name' => 'johndoe-eph123456',
'parent' => 'johndoe',
'type' => 'ephemeral',
'type' => 'brancher',
])),
);

$ephemeralAppName = $this->client->ephemeralApp->create('johndoe');
$brancherAppName = $this->client->brancherApp->create('johndoe');

$request = $this->responses->getLastRequest();
$this->assertEquals('POST', $request->getMethod());
$this->assertEquals('/v2/app/johndoe/ephemeral/', $request->getUri());
$this->assertEquals('johndoe-eph123456', $ephemeralAppName);
$this->assertEquals('/v2/app/johndoe/brancher/', $request->getUri());
$this->assertEquals('johndoe-eph123456', $brancherAppName);
}

public function testCreateEphemeralAppRaisesClientExceptions()
public function testCreateBrancherAppRaisesClientExceptions()
{
$badRequestResponse = new Response(400, [], json_encode([
'non_field_errors' => ['Your request was invalid.']
Expand All @@ -38,10 +38,10 @@ public function testCreateEphemeralAppRaisesClientExceptions()

$this->expectExceptionObject(new HypernodeApiClientException($badRequestResponse));

$this->client->ephemeralApp->create('johndoe');
$this->client->brancherApp->create('johndoe');
}

public function testCreateEphemeralAppRaisesServerExceptions()
public function testCreateBrancherAppRaisesServerExceptions()
{
$badRequestResponse = new Response(500, [], json_encode([
'non_field_errors' => ['Something went wrong processing your request.']
Expand All @@ -50,23 +50,23 @@ public function testCreateEphemeralAppRaisesServerExceptions()

$this->expectExceptionObject(new HypernodeApiServerException($badRequestResponse));

$this->client->ephemeralApp->create('johndoe');
$this->client->brancherApp->create('johndoe');
}

public function testCancelEphemeralApp()
public function testCancelBrancherApp()
{
$this->responses->append(
new Response(204, [], null),
);

$this->client->ephemeralApp->cancel('johndoe-eph123456');
$this->client->brancherApp->cancel('johndoe-eph123456');

$request = $this->responses->getLastRequest();
$this->assertEquals('POST', $request->getMethod());
$this->assertEquals('/v2/app/johndoe-eph123456/cancel/', $request->getUri());
}

public function testCancelEphemeralAppRaisesClientExceptions()
public function testCancelBrancherAppRaisesClientExceptions()
{
$badRequestResponse = new Response(400, [], json_encode([
'non_field_errors' => ['Your request was invalid.']
Expand All @@ -75,10 +75,10 @@ public function testCancelEphemeralAppRaisesClientExceptions()

$this->expectExceptionObject(new HypernodeApiClientException($badRequestResponse));

$this->client->ephemeralApp->cancel('johndoe');
$this->client->brancherApp->cancel('johndoe');
}

public function testCancelEphemeralAppRaisesServerExceptions()
public function testCancelBrancherAppRaisesServerExceptions()
{
$badRequestResponse = new Response(500, [], json_encode([
'non_field_errors' => ['Something went wrong processing your request.']
Expand All @@ -87,6 +87,6 @@ public function testCancelEphemeralAppRaisesServerExceptions()

$this->expectExceptionObject(new HypernodeApiServerException($badRequestResponse));

$this->client->ephemeralApp->cancel('johndoe');
$this->client->brancherApp->cancel('johndoe');
}
}