Skip to content
Draft
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
96 changes: 96 additions & 0 deletions .github/workflows/sync-crossconnectsv2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Sync crossconnectsv2 API spec

on:
workflow_dispatch:

jobs:
sync:
strategy:
matrix:
java-version: [11.0.21]
java-distribution: [temurin]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"

- name: Install Java
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: ${{ matrix.java-distribution }}

- name: Checkout code
uses: actions/checkout@v4

- name: GitHub user
run: |
# https://api.github.com/users/github-actions[bot]
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'

- name: Fetch latest spec
id: fetch
run: |
make -f Makefile.crossconnectsv2 fetch
git add spec/services/crossconnectsv2
echo `git commit -m 'sync: fetch ${{ steps.date.outputs.date }} spec'`

- name: Apply spec patches
id: patch
if: ${{ always() && steps.fetch.conclusion == 'success' }}
run: |
make -f Makefile.crossconnectsv2 patch
git add spec/services/crossconnectsv2
echo `git commit -m 'sync: patch spec with ${{ steps.date.outputs.date }} spec'`

- name: Generate code
id: generate
if: ${{ always() && steps.fetch.conclusion == 'success' }}
run: |
make -f Makefile.crossconnectsv2 generate
git add services/crossconnectsv2
echo `git commit -m 'sync: generate client with ${{ steps.date.outputs.date }} spec'`

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v7
if: ${{ always() && steps.fetch.conclusion == 'success' }}
with:
branch: sync/gh
branch-suffix: timestamp
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
commit-message: "sync: uncommitted changes detected when opening PR"
title: "feat: API Sync by GitHub Action for @${{ github.event.sender.login }}"
body: |
This API Sync PR was triggered by @${{ github.event.sender.login }} through [GitHub Actions workflow_displatch](https://github.com/equinix/equinix-sdk-go/actions?query=event%3Aworkflow_dispatch)
on ${{ steps.date.outputs.date }}.

* latest Swagger is fetched
* patches have been applied
* generated client has been updated
delete-branch: true
draft: ${{ steps.patch.conclusion == 'failure' || steps.generate.conclusion == 'failure' }}

- name: Comment for failed patch
uses: mshick/add-pr-comment@v2
if: ${{ always() && steps.patch.conclusion == 'failure' && steps.cpr.conclusion == 'success' }}
with:
issue: ${{ steps.cpr.outputs.pull-request-number }}
message: Failed to patch latest spec. Someone with write access must review and, if necessary, fix this PR manually and then convert it from Draft status to Ready for Review.

- name: Comment for failed generate
uses: mshick/add-pr-comment@v2
if: ${{ always() && steps.generate.conclusion == 'failure' && steps.cpr.conclusion == 'success' }}
with:
issue: ${{ steps.cpr.outputs.pull-request-number }}
message: Failed to generate code from latest patched spec. Someone with write access must fix this PR manually and then convert it from Draft status to Ready for Review.

- name: Check outputs
if: ${{ always() && steps.cpr.conclusion == 'success' }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
65 changes: 65 additions & 0 deletions Makefile.crossconnectsv2
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.PHONY: all pull fetch patch generate clean codegen mod docs move-other patch-post fmt test stage

include Makefile

PACKAGE_NAME=crossconnectsv2
SPEC_BASE_URL:=https://docs.equinix.com/api-catalog/crossconnectsv2
SPEC_ROOT_FILE:=openapi.yaml

CODE_DIR=services/${PACKAGE_NAME}
TEMPLATE_DIR=${TEMPLATE_BASE_DIR}/${PACKAGE_NAME}
SPEC_FETCHED_DIR=${SPEC_BASE_DIR}/${PACKAGE_NAME}/oas3.fetched
SPEC_PATCH_DIR=${SPEC_BASE_DIR}/${PACKAGE_NAME}/patches
SPEC_PATCHED_DIR=${SPEC_BASE_DIR}/${PACKAGE_NAME}/oas3.patched
SPEC_FETCHER=curl

ARTIFACT_ID=${GIT_REPO}-${PACKAGE_NAME}

all: pull fetch patch generate stage

generate: clean codegen patch-post fmt test

pull:
${CRI} pull ${OPENAPI_IMAGE}

fetch:
${SPEC_FETCHER} -o ${SPEC_FETCHED_DIR}/${SPEC_ROOT_FILE} ${SPEC_BASE_URL}/${SPEC_ROOT_FILE}

patch:
rm -rf ${SPEC_PATCHED_DIR}
cp -r ${SPEC_FETCHED_DIR} ${SPEC_PATCHED_DIR}

for diff in $(shell set -x; find ${SPEC_PATCH_DIR} -name '*.patch' | sort -n); do \
patch --no-backup-if-mismatch -N -t -p1 -i $$diff; \
RESULT=$$(($${RESULT} + $$?)); \
done; \
exit $$RESULT;

patch-post:
# patch is idempotent, always starting with the generated files
for diff in $(shell find patches/services/${PACKAGE_NAME} -name \*.patch | sort -n); do \
patch --no-backup-if-mismatch -N -t -p1 -i $$diff; \
done

clean:
rm -rf $(CODE_DIR)

codegen:
${OPENAPI_GENERATOR} generate -g java \
--http-user-agent "${USER_AGENT}" \
-p artifactVersion=${PACKAGE_VERSION} \
-p artifactId="${PACKAGE_NAME}" \
-p invokerPackage="com.equinix.sdk.${PACKAGE_NAME}" \
-p apiPackage="com.equinix.sdk.${PACKAGE_NAME}.api" \
-p modelPackage="com.equinix.sdk.${PACKAGE_NAME}.model" \
-i ${SPEC_PATCHED_DIR}/${SPEC_ROOT_FILE} \
-t ${TEMPLATE_DIR} \
-c config/openapi-generator.json \
-o ${CODE_DIR} \
--git-repo-id ${GIT_REPO} \
--git-user-id ${GIT_ORG}

validate:
${OPENAPI_GENERATOR} validate \
--recommend \
-i ${SPEC_PATCHED_DIR}/${SPEC_ROOT_FILE}
5 changes: 5 additions & 0 deletions equinix-sdk-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@
<artifactId>fabricv4</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.equinix.sdk</groupId>
<artifactId>crossconnectsv2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
24 changes: 24 additions & 0 deletions examples/crossconnectsv2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# crossconnectsv2 examples

Examples for the Equinix Cross Connects v2 service. See [examples/README.md](../README.md) for the
environment variables and how to run them.

The service only has operations that create or modify orders, so the three order examples below do
not send anything unless `EQUINIX_EXAMPLE_ALLOW_WRITES=true` is set. They build a realistic request
and print how to opt in otherwise. Clients here are not expected to match the earlier standalone
samples 1:1; the examples follow the maintained, spec-generated SDK.

| Example | Shows | Replaces (earlier sample operation) |
| --- | --- | --- |
| `OrderCrossConnect` | ordering a standard fiber cross connect between two patch panels (creates an order, guarded) | standard, intracustomer, extended and fiber cross connect orders |
| `RequestDeinstall` | ordering the removal of an existing cross connect by asset ID (guarded) | cross connect deinstall order |
| `UpdateOrderContacts` | adding a notification contact to an existing order (modifies an order, guarded) | none |
| `HandleCrossConnectErrors` | catching `ApiException`, reading status, headers and body, parsing `ErrorDetails`; sends an invalid token so nothing is created | none |

The service has no read operations, so there is no order retrieval example. It also has no list or
search operations, so there is no pagination example. The earlier sample's lookups (providers,
locations, types, connection services, patch panels) belong to other services and are not part of this
one.

`OrderCrossConnect` uses `EQUINIX_EXAMPLE_ALLOW_WRITES`; `RequestDeinstall` also reads
`EQUINIX_EXAMPLE_ASSET_ID` and `UpdateOrderContacts` reads `EQUINIX_EXAMPLE_ORDER_ID`.
24 changes: 24 additions & 0 deletions examples/crossconnectsv2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.equinix.sdk</groupId>
<artifactId>equinix-sdk-java-examples</artifactId>
<version>0.11.0</version>
</parent>
<artifactId>examples-crossconnectsv2</artifactId>
<name>examples-crossconnectsv2</name>

<dependencies>
<dependency>
<groupId>com.equinix.sdk</groupId>
<artifactId>crossconnectsv2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.equinix.sdk</groupId>
<artifactId>examples-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.equinix.sdk.examples.crossconnectsv2;

import com.equinix.sdk.crossconnectsv2.ApiClient;
import com.equinix.sdk.crossconnectsv2.ApiException;
import com.equinix.sdk.crossconnectsv2.Configuration;
import com.equinix.sdk.crossconnectsv2.JSON;
import com.equinix.sdk.crossconnectsv2.api.CrossConnectsApi;
import com.equinix.sdk.crossconnectsv2.auth.HttpBearerAuth;
import com.equinix.sdk.crossconnectsv2.model.ErrorDetails;
import com.equinix.sdk.crossconnectsv2.model.Layer1Create;
import com.equinix.sdk.examples.ExampleEnv;

/**
* Shows how failures surface: every non-2xx response is thrown as an {@link ApiException} carrying the
* HTTP status, response headers and raw body, and the body can be parsed into the service's error
* model.
*
* <p>Deliberately authenticates with an invalid token so that the order request is refused before
* anything is created. It needs no credentials and creates no resources.
*/
public class HandleCrossConnectErrors {
public static void main(String[] args) {
ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath(ExampleEnv.endpoint());
((HttpBearerAuth) client.getAuthentication("BearerAuth")).setBearerToken("not-a-real-token");
CrossConnectsApi api = new CrossConnectsApi(client);

try {
api.orderCrossConnects(new Layer1Create());
System.out.println("unexpectedly succeeded");
} catch (ApiException e) {
System.out.println("HTTP status: " + e.getCode());
System.out.println("headers: " + e.getResponseHeaders());
try {
ErrorDetails error = JSON.getGson().fromJson(e.getResponseBody(), ErrorDetails.class);
System.out.println("error code: " + error.getErrorCode());
System.out.println("message: " + error.getErrorMessage());
System.out.println("correlation: " + error.getCorrelationId());
} catch (RuntimeException notJson) {
// gateways and proxies can return non-JSON bodies, e.g. for 502/503
System.out.println("raw body: " + e.getResponseBody());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.equinix.sdk.examples.crossconnectsv2;

import com.equinix.sdk.crossconnectsv2.ApiClient;
import com.equinix.sdk.crossconnectsv2.ApiException;
import com.equinix.sdk.crossconnectsv2.ApiResponse;
import com.equinix.sdk.crossconnectsv2.Configuration;
import com.equinix.sdk.crossconnectsv2.api.CrossConnectsApi;
import com.equinix.sdk.crossconnectsv2.auth.HttpBearerAuth;
import com.equinix.sdk.crossconnectsv2.model.ASide;
import com.equinix.sdk.crossconnectsv2.model.ConnectionServices;
import com.equinix.sdk.crossconnectsv2.model.ContactRequestRegisteredUser;
import com.equinix.sdk.crossconnectsv2.model.ConnectorTypes;
import com.equinix.sdk.crossconnectsv2.model.Layer1Create;
import com.equinix.sdk.crossconnectsv2.model.Layer1CreateContactsInner;
import com.equinix.sdk.crossconnectsv2.model.Layer1Details;
import com.equinix.sdk.crossconnectsv2.model.MediaTypes;
import com.equinix.sdk.crossconnectsv2.model.PatchPanel;
import com.equinix.sdk.crossconnectsv2.model.ProtocolTypes;
import com.equinix.sdk.crossconnectsv2.model.ZSide;
import com.equinix.sdk.crossconnectsv2.model.ZSideWithPatchPanel;
import com.equinix.sdk.examples.ExampleEnv;
import java.math.BigDecimal;

/**
* Orders one standard single mode fiber cross connect between two patch panels.
*
* <p>Creates an order, which Equinix will then fulfil, so it only sends the request when
* EQUINIX_EXAMPLE_ALLOW_WRITES=true. Replace the patch panel IDs and contact below with your own
* (look them up in the Lookup API) before enabling it.
*/
public class OrderCrossConnect {
public static void main(String[] args) throws Exception {
ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath(ExampleEnv.endpoint());
((HttpBearerAuth) client.getAuthentication("BearerAuth")).setBearerToken(ExampleEnv.token());
CrossConnectsApi api = new CrossConnectsApi(client);

// one entry in details is one cross connect; add more entries to order several in one request
Layer1Create order = new Layer1Create()
.customerReferenceId("example-order-1")
.description("Created from the SDK examples")
.addDetailsItem(new Layer1Details()
.aSide(new ASide()
.connectionService(ConnectionServices.SINGLE_MODE_FIBER)
.mediaType(MediaTypes.SINGLE_MODE_FIBER)
.protocolType(ProtocolTypes._10_GIG_ETHERNET)
.connectorType(ConnectorTypes.FC)
.patchPanel(new PatchPanel().id("CP:0104:1199890").portA(new BigDecimal(12)).portB(new BigDecimal(13))))
// zSide and contacts are oneOf types: wrap the variant that applies. This one
// connects to an existing patch panel; ZSideWithLOA is for a new provider.
.zSide(new ZSide(new ZSideWithPatchPanel()
.connectorType(ConnectorTypes.LC)
.circuitId("1-12312312")
.patchPanel(new PatchPanel().id("PP:0104:1190123")))))
.addContactsItem(new Layer1CreateContactsInner(new ContactRequestRegisteredUser()
.type(ContactRequestRegisteredUser.TypeEnum.NOTIFICATION)
.addRegisteredUsersItem("john_doe")));

if (!WriteGuard.allowed()) {
return;
}

try {
ApiResponse<Void> response = api.orderCrossConnectsWithHttpInfo(order);
System.out.println("HTTP status: " + response.getStatusCode());
System.out.println("order: " + response.getHeaders().get("Location"));
} catch (ApiException e) {
System.out.println("order rejected with HTTP " + e.getCode() + ": " + e.getResponseBody());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.equinix.sdk.examples.crossconnectsv2;

import com.equinix.sdk.crossconnectsv2.ApiClient;
import com.equinix.sdk.crossconnectsv2.ApiException;
import com.equinix.sdk.crossconnectsv2.ApiResponse;
import com.equinix.sdk.crossconnectsv2.Configuration;
import com.equinix.sdk.crossconnectsv2.api.CrossConnectsApi;
import com.equinix.sdk.crossconnectsv2.auth.HttpBearerAuth;
import com.equinix.sdk.crossconnectsv2.model.Layer1DeinstallDetails;
import com.equinix.sdk.crossconnectsv2.model.Layer1DeinstallRequest;
import com.equinix.sdk.examples.ExampleEnv;
import java.time.LocalDate;

/**
* Places an order to remove an existing cross connect.
*
* <p>Requests the removal of real infrastructure, so it only sends the request when
* EQUINIX_EXAMPLE_ALLOW_WRITES=true. Set EQUINIX_EXAMPLE_ASSET_ID to the asset ID of the cross
* connect to remove; the removal date is one week from today.
*/
public class RequestDeinstall {
public static void main(String[] args) throws Exception {
ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath(ExampleEnv.endpoint());
((HttpBearerAuth) client.getAuthentication("BearerAuth")).setBearerToken(ExampleEnv.token());
CrossConnectsApi api = new CrossConnectsApi(client);

String assetId = System.getenv().getOrDefault("EQUINIX_EXAMPLE_ASSET_ID", "4-1234567890");
Layer1DeinstallRequest request = new Layer1DeinstallRequest()
.customerReferenceId("example-deinstall-1")
.description("Created from the SDK examples")
.removalDate(LocalDate.now().plusDays(7))
.addDetailsItem(new Layer1DeinstallDetails()
.assetId(assetId)
// false: do not proceed if Equinix detects live traffic on the connection
.proceedWithLiveTraffic(false));

if (!WriteGuard.allowed()) {
return;
}

try {
ApiResponse<Void> response = api.placeCrossConnectDeinstallationOrderWithHttpInfo(request);
System.out.println("HTTP status: " + response.getStatusCode());
System.out.println("order: " + response.getHeaders().get("Location"));
} catch (ApiException e) {
System.out.println("deinstall rejected with HTTP " + e.getCode() + ": " + e.getResponseBody());
}
}
}
Loading
Loading