Skip to content

Commit

Permalink
CPP: Remove deprecated DescribeEndpoints (awsdocs#6056)
Browse files Browse the repository at this point in the history
* removed deprecated DescribeEndpoints code.
  • Loading branch information
meyertst-aws authored Feb 6, 2024
1 parent 4ab4542 commit 7bba523
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 280 deletions.
3 changes: 0 additions & 3 deletions .doc_gen/metadata/mediaconvert_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ mediaconvert_CreateJob:
excerpts:
- description:
snippet_tags:
- cpp.example_code.mediaconvert.get_endpoint_uri_helper
- cpp.example_code.mediaconvert.CreateJob
services:
mediaconvert: {CreateJob}
Expand Down Expand Up @@ -109,7 +108,6 @@ mediaconvert_ListJobs:
excerpts:
- description:
snippet_tags:
- cpp.example_code.mediaconvert.get_endpoint_uri_helper
- cpp.example_code.mediaconvert.ListJobs
services:
mediaconvert: {ListJobs}
Expand Down Expand Up @@ -158,7 +156,6 @@ mediaconvert_GetJob:
excerpts:
- description:
snippet_tags:
- cpp.example_code.mediaconvert.get_endpoint_uri_helper
- cpp.example_code.mediaconvert.GetJob
services:
mediaconvert: {GetJob}
3 changes: 1 addition & 2 deletions cpp/example_code/mediaconvert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ foreach (file ${AWSDOC_SOURCE})
set(EXAMPLE_EXE run_${EXAMPLE})

add_executable(${EXAMPLE_EXE}
${file}
utils.cpp)
${file})

target_link_libraries(${EXAMPLE_EXE} ${AWSSDK_LINK_LIBRARIES}
${AWSSDK_PLATFORM_DEPS})
Expand Down
11 changes: 7 additions & 4 deletions cpp/example_code/mediaconvert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Next, for information on code example structures and how to build and run the ex

Code excerpts that show you how to call individual service functions.

- [Create a transcoding job](create_job.cpp#L52) (`CreateJob`)
- [Get a transcoding job](get_job.cpp#L22) (`GetJob`)
- [List transcoding jobs](list_jobs.cpp#L22) (`ListJobs`)
- [Create a transcoding job](create_job.cpp#L49) (`CreateJob`)
- [Get a transcoding job](get_job.cpp#L20) (`GetJob`)
- [List transcoding jobs](list_jobs.cpp#L20) (`ListJobs`)


<!--custom.examples.start-->
Expand All @@ -53,7 +53,7 @@ Code excerpts that show you how to call individual service functions.

### Instructions

An executable is built for each source file. These executables are located in the build folder and have
An executable is built for each source file in this folder. These executables are located in the build folder and have
"run_" prepended to the source file name, minus the suffix. See the "main" function in the source file for further instructions.

For example, to run the action in the source file "my_action.cpp", execute the following command from within the build folder. The command
Expand All @@ -63,6 +63,9 @@ will display any required arguments.
./run_my_action
```

If the source file is in a different folder, instructions can be found in the README in that
folder.

<!--custom.instructions.start-->
MediaConvert has a low request limit for DescribeEndpoints.
The best practice is to request the endpoint once, and then cache it.
Expand Down
16 changes: 1 addition & 15 deletions cpp/example_code/mediaconvert/create_job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <aws/core/Aws.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/mediaconvert/MediaConvertClient.h>
#include <aws/mediaconvert/model/DescribeEndpointsRequest.h>
#include <aws/mediaconvert/model/CreateJobRequest.h>
#include "mediaconvert_samples.h"
#include <fstream>
Expand Down Expand Up @@ -65,15 +64,6 @@ bool AwsDoc::MediaConvert::createJob(const Aws::String &mediaConvertRole,
const Aws::String &fileOutput,
const Aws::String &jobSettingsFile,
const Aws::Client::ClientConfiguration &clientConfiguration) {
// MediaConvert has a low request limit for DescribeEndpoints.
// "getEndpointUriHelper" uses caching to limit requests.
// See utils.cpp.
Aws::String endpoint = getEndpointUriHelper(clientConfiguration);
if (endpoint.empty()) {
std::cerr << "createJob error getting endpoint." << std::endl;
return false;
}

Aws::MediaConvert::Model::CreateJobRequest createJobRequest;

createJobRequest.SetRole(mediaConvertRole);
Expand Down Expand Up @@ -262,10 +252,7 @@ bool AwsDoc::MediaConvert::createJob(const Aws::String &mediaConvertRole,
createJobRequest.SetSettings(jobSettings);
}

Aws::Client::ClientConfiguration endpointClientConfiguration(clientConfiguration);
endpointClientConfiguration.endpointOverride = endpoint;

Aws::MediaConvert::MediaConvertClient client(endpointClientConfiguration);
Aws::MediaConvert::MediaConvertClient client(clientConfiguration);
Aws::MediaConvert::Model::CreateJobOutcome outcome = client.CreateJob(
createJobRequest);
if (outcome.IsSuccess()) {
Expand Down Expand Up @@ -312,7 +299,6 @@ int main(int argc, char **argv) {

// Initialize the AWS SDK for C++.
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;
Aws::InitAPI(options);
{
std::string mediaConvertRole = argv[1];
Expand Down
85 changes: 0 additions & 85 deletions cpp/example_code/mediaconvert/describe_endpoints.cpp

This file was deleted.

37 changes: 13 additions & 24 deletions cpp/example_code/mediaconvert/get_job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,22 @@
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc::MediaConvert::getJob(const Aws::String& jobID,
const Aws::Client::ClientConfiguration &clientConfiguration) {
// AWS Elemental MediaConvert has a low request limit for DescribeEndpoints.
// "getEndpointUriHelper" uses caching to limit requests.
// See utils.cpp.
Aws::String endpoint = getEndpointUriHelper(clientConfiguration);

if (endpoint.empty())
{
return false;
}

Aws::Client::ClientConfiguration endpointConfiguration(clientConfiguration);
endpointConfiguration.endpointOverride = endpoint;
Aws::MediaConvert::MediaConvertClient client(endpointConfiguration);
bool AwsDoc::MediaConvert::getJob(const Aws::String &jobID,
const Aws::Client::ClientConfiguration &clientConfiguration) {
Aws::MediaConvert::MediaConvertClient client(clientConfiguration);

Aws::MediaConvert::Model::GetJobRequest request;
request.SetId(jobID);
const Aws::MediaConvert::Model::GetJobOutcome outcome = client.GetJob(
request);
if (outcome.IsSuccess()) {
std::cout << outcome.GetResult().GetJob().Jsonize().View().WriteReadable() << std::endl;
}
else {
std::cerr << "DescribeEndpoints error - " << outcome.GetError().GetMessage()
<< std::endl;
}
const Aws::MediaConvert::Model::GetJobOutcome outcome = client.GetJob(
request);
if (outcome.IsSuccess()) {
std::cout << outcome.GetResult().GetJob().Jsonize().View().WriteReadable()
<< std::endl;
}
else {
std::cerr << "DescribeEndpoints error - " << outcome.GetError().GetMessage()
<< std::endl;
}


return outcome.IsSuccess();
Expand Down
14 changes: 1 addition & 13 deletions cpp/example_code/mediaconvert/list_jobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,7 @@
bool AwsDoc::MediaConvert::listJobs(
const Aws::Client::ClientConfiguration &clientConfiguration) {

// AWS Elemental MediaConvert has a low request limit for DescribeEndpoints.
// "getEndpointUriHelper" uses caching to limit requests.
// See utils.cpp.
Aws::String endpoint = getEndpointUriHelper(clientConfiguration);

if (endpoint.empty())
{
return false;
}

Aws::Client::ClientConfiguration endpointConfiguration(clientConfiguration);
endpointConfiguration.endpointOverride = endpoint;
Aws::MediaConvert::MediaConvertClient client(endpointConfiguration);
Aws::MediaConvert::MediaConvertClient client(clientConfiguration);

bool result = true;
Aws::String nextToken; // Used to handle paginated results.
Expand Down
10 changes: 0 additions & 10 deletions cpp/example_code/mediaconvert/mediaconvert_samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace AwsDoc {
namespace MediaConvert {
extern const char CACHED_ENDPOINT_FILE[];

//! Create a an AWS Elemental MediaConvert job.
/*!
\param mediaConvertRole: An Amazon Resource Name (ARN) for the AWS Identity
Expand Down Expand Up @@ -51,14 +49,6 @@ namespace AwsDoc {
*/
bool getJob(const Aws::String &jobID,
const Aws::Client::ClientConfiguration &clientConfiguration);

//! Utility routine to handle caching of a retrieved endpoint.
/*!
\param clientConfiguration: AWS client configuration.
\return Aws::String: The endpoint URI.
*/
Aws::String getEndpointUriHelper(
const Aws::Client::ClientConfiguration &clientConfiguration);
} // namespace MediaConvert
} // namespace AwsDoc

Expand Down
1 change: 0 additions & 1 deletion cpp/example_code/mediaconvert/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ target_sources(
PUBLIC
${GTEST_SOURCE}
test_main.cpp
../utils.cpp
${EXAMPLE_SERVICE_NAME}_gtests.cpp
)

Expand Down
25 changes: 0 additions & 25 deletions cpp/example_code/mediaconvert/tests/MediaConvert_gtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#include <fstream>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/mediaconvert/MediaConvertClient.h>
#include <aws/mediaconvert/model/DescribeEndpointsRequest.h>
#include <aws/testing/mocks/http/MockHttpClient.h>
#include "mediaconvert_samples.h"

// Debug testing framework start.
#include <aws/core/utils/logging/ConsoleLogSystem.h>
Expand Down Expand Up @@ -69,8 +67,6 @@ void AwsDocTest::MediaConvert_GTests::SetUp() {
// The following code is needed for the AwsDocTest::MyStringBuffer::underflow exception.
// Otherwise, an infinite loop occurs when looping for a result on an empty buffer.
std::cin.exceptions(std::ios_base::badbit);

createEndpointCache();
}

void AwsDocTest::MediaConvert_GTests::TearDown() {
Expand Down Expand Up @@ -106,27 +102,6 @@ bool AwsDocTest::MediaConvert_GTests::suppressStdOut() {
return false; // Temporary override to debug testing framework.
}

void AwsDocTest::MediaConvert_GTests::createEndpointCache() {
Aws::MediaConvert::MediaConvertClient endpointClient(*s_clientConfig);
Aws::MediaConvert::Model::DescribeEndpointsRequest request;
auto outcome = endpointClient.DescribeEndpoints(request);
Aws::String endpoint = "aaaaaaa.mediaconvert.us-test.amazonaws.com";
if (outcome.IsSuccess()) {
auto endpoints = outcome.GetResult().GetEndpoints();
if (!endpoints.empty()) {
// Need to strip https:// from endpoint for C++.
endpoint = endpoints[0].GetUrl().substr(8);
}
}
else {
std::cerr << "DescribeEndpoints error - " << outcome.GetError().GetMessage()
<< std::endl;
}
std::ofstream endpointCacheOut(AwsDoc::MediaConvert::CACHED_ENDPOINT_FILE);
endpointCacheOut << endpoint;
}


int AwsDocTest::MyStringBuffer::underflow() {
int result = basic_stringbuf::underflow();
if (result == EOF) {
Expand Down
3 changes: 0 additions & 3 deletions cpp/example_code/mediaconvert/tests/MediaConvert_gtests.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ namespace AwsDocTest {
// after InitAPI.
static std::unique_ptr<Aws::Client::ClientConfiguration> s_clientConfig;

// This endpoint cache must be created in SetUp to make sure that mocks work correctly.
void createEndpointCache();

private:

bool suppressStdOut();
Expand Down
24 changes: 0 additions & 24 deletions cpp/example_code/mediaconvert/tests/gtest_describe_endpoints.cpp

This file was deleted.

Loading

0 comments on commit 7bba523

Please sign in to comment.