기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
1단계: 새 원장 생성
이 단계에서는 이라는 vehicle-registration
새 Amazon QLDB 원장을 생성합니다.
새 원장을 생성하려면
-
이 자습서의 다른 모든 프로그램에서 사용하는 상수 값이 들어 있는 다음 파일(Constants.java
)을 검토하세요.
- 2.x
-
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package software.amazon.qldb.tutorial;
import com.amazon.ion.IonSystem;
import com.amazon.ion.system.IonSystemBuilder;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper;
import com.fasterxml.jackson.dataformat.ion.ionvalue.IonValueMapper;
/**
* Constant values used throughout this tutorial.
*/
public final class Constants {
public static final int RETRY_LIMIT = 4;
public static final String LEDGER_NAME = "vehicle-registration";
public static final String STREAM_NAME = "vehicle-registration-stream";
public static final String VEHICLE_REGISTRATION_TABLE_NAME = "VehicleRegistration";
public static final String VEHICLE_TABLE_NAME = "Vehicle";
public static final String PERSON_TABLE_NAME = "Person";
public static final String DRIVERS_LICENSE_TABLE_NAME = "DriversLicense";
public static final String VIN_INDEX_NAME = "VIN";
public static final String PERSON_GOV_ID_INDEX_NAME = "GovId";
public static final String VEHICLE_REGISTRATION_LICENSE_PLATE_NUMBER_INDEX_NAME = "LicensePlateNumber";
public static final String DRIVER_LICENSE_NUMBER_INDEX_NAME = "LicenseNumber";
public static final String DRIVER_LICENSE_PERSONID_INDEX_NAME = "PersonId";
public static final String JOURNAL_EXPORT_S3_BUCKET_NAME_PREFIX = "qldb-tutorial-journal-export";
public static final String USER_TABLES = "information_schema.user_tables";
public static final String LEDGER_NAME_WITH_TAGS = "tags";
public static final IonSystem SYSTEM = IonSystemBuilder.standard().build();
public static final IonObjectMapper MAPPER = new IonValueMapper(SYSTEM);
private Constants() { }
static {
MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
}
- 1.x
-
Amazon Ion 패키지의 경우 애플리케이션에서 네임스페이스 com.amazon.ion
을 사용해야 합니다. 네임스페이스 software.amazon.ion
아래의 다른 Ion 패키지에 AWS SDK for Java 따라 다르지만 이 패키지는 드라이버와 호환되지 않는 레거시 패키지입니다. QLDB
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package software.amazon.qldb.tutorial;
import com.amazon.ion.IonSystem;
import com.amazon.ion.system.IonSystemBuilder;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper;
import com.fasterxml.jackson.dataformat.ion.ionvalue.IonValueMapper;
/**
* Constant values used throughout this tutorial.
*/
public final class Constants {
public static final int RETRY_LIMIT = 4;
public static final String LEDGER_NAME = "vehicle-registration";
public static final String STREAM_NAME = "vehicle-registration-stream";
public static final String VEHICLE_REGISTRATION_TABLE_NAME = "VehicleRegistration";
public static final String VEHICLE_TABLE_NAME = "Vehicle";
public static final String PERSON_TABLE_NAME = "Person";
public static final String DRIVERS_LICENSE_TABLE_NAME = "DriversLicense";
public static final String VIN_INDEX_NAME = "VIN";
public static final String PERSON_GOV_ID_INDEX_NAME = "GovId";
public static final String VEHICLE_REGISTRATION_LICENSE_PLATE_NUMBER_INDEX_NAME = "LicensePlateNumber";
public static final String DRIVER_LICENSE_NUMBER_INDEX_NAME = "LicenseNumber";
public static final String DRIVER_LICENSE_PERSONID_INDEX_NAME = "PersonId";
public static final String JOURNAL_EXPORT_S3_BUCKET_NAME_PREFIX = "qldb-tutorial-journal-export";
public static final String USER_TABLES = "information_schema.user_tables";
public static final String LEDGER_NAME_WITH_TAGS = "tags";
public static final IonSystem SYSTEM = IonSystemBuilder.standard().build();
public static final IonObjectMapper MAPPER = new IonValueMapper(SYSTEM);
private Constants() { }
static {
MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
}
이 Constants
클래스에는 오픈 소스 Jackson IonValueMapper
클래스의 인스턴스가 포함되어 있습니다. 읽기 및 쓰기 트랜잭션을 수행할 때 이 매퍼를 사용하여 Amazon Ion 데이터를 처리할 수 있습니다.
또한 CreateLedger.java
파일은 원장의 현재 상태를 설명하는 다음 프로그램(DescribeLedger.java
)에 대한 종속성을 가집니다.
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package software.amazon.qldb.tutorial;
import com.amazonaws.services.qldb.AmazonQLDB;
import com.amazonaws.services.qldb.model.DescribeLedgerRequest;
import com.amazonaws.services.qldb.model.DescribeLedgerResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Describe a QLDB ledger.
*
* This code expects that you have AWS credentials setup per:
* http://docs.aws.amazon.com/java-sdk/latest/developer-guide/setup-credentials.html
*/
public final class DescribeLedger {
public static AmazonQLDB client = CreateLedger.getClient();
public static final Logger log = LoggerFactory.getLogger(DescribeLedger.class);
private DescribeLedger() { }
public static void main(final String... args) {
try {
describe(Constants.LEDGER_NAME);
} catch (Exception e) {
log.error("Unable to describe a ledger!", e);
}
}
/**
* Describe a ledger.
*
* @param name
* Name of the ledger to describe.
* @return {@link DescribeLedgerResult} from QLDB.
*/
public static DescribeLedgerResult describe(final String name) {
log.info("Let's describe ledger with name: {}...", name);
DescribeLedgerRequest request = new DescribeLedgerRequest().withName(name);
DescribeLedgerResult result = client.describeLedger(request);
log.info("Success. Ledger description: {}", result);
return result;
}
}
-
CreateLedger.java
프로그램을 컴파일하고 실행하여 vehicle-registration
라는 이름의 원장을 생성합니다.
- 2.x
-
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package software.amazon.qldb.tutorial;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.qldb.AmazonQLDB;
import com.amazonaws.services.qldb.AmazonQLDBClientBuilder;
import com.amazonaws.services.qldb.model.CreateLedgerRequest;
import com.amazonaws.services.qldb.model.CreateLedgerResult;
import com.amazonaws.services.qldb.model.DescribeLedgerResult;
import com.amazonaws.services.qldb.model.LedgerState;
import com.amazonaws.services.qldb.model.PermissionsMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Create a ledger and wait for it to be active.
* <p>
* This code expects that you have AWS credentials setup per:
* http://docs.aws.amazon.com/java-sdk/latest/developer-guide/setup-credentials.html
*/
public final class CreateLedger {
public static final Logger log = LoggerFactory.getLogger(CreateLedger.class);
public static final Long LEDGER_CREATION_POLL_PERIOD_MS = 10_000L;
public static String endpoint = null;
public static String region = null;
public static AmazonQLDB client = getClient();
private CreateLedger() {
}
/**
* Build a low-level QLDB client.
*
* @return {@link AmazonQLDB} control plane client.
*/
public static AmazonQLDB getClient() {
AmazonQLDBClientBuilder builder = AmazonQLDBClientBuilder.standard();
if (null != endpoint && null != region) {
builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region));
}
return builder.build();
}
public static void main(final String... args) throws Exception {
try {
client = getClient();
create(Constants.LEDGER_NAME);
waitForActive(Constants.LEDGER_NAME);
} catch (Exception e) {
log.error("Unable to create the ledger!", e);
throw e;
}
}
/**
* Create a new ledger with the specified ledger name.
*
* @param ledgerName Name of the ledger to be created.
* @return {@link CreateLedgerResult} from QLDB.
*/
public static CreateLedgerResult create(final String ledgerName) {
log.info("Let's create the ledger with name: {}...", ledgerName);
CreateLedgerRequest request = new CreateLedgerRequest()
.withName(ledgerName)
.withPermissionsMode(PermissionsMode.ALLOW_ALL);
CreateLedgerResult result = client.createLedger(request);
log.info("Success. Ledger state: {}.", result.getState());
return result;
}
/**
* Wait for a newly created ledger to become active.
*
* @param ledgerName Name of the ledger to wait on.
* @return {@link DescribeLedgerResult} from QLDB.
* @throws InterruptedException if thread is being interrupted.
*/
public static DescribeLedgerResult waitForActive(final String ledgerName) throws InterruptedException {
log.info("Waiting for ledger to become active...");
while (true) {
DescribeLedgerResult result = DescribeLedger.describe(ledgerName);
if (result.getState().equals(LedgerState.ACTIVE.name())) {
log.info("Success. Ledger is active and ready to use.");
return result;
}
log.info("The ledger is still creating. Please wait...");
Thread.sleep(LEDGER_CREATION_POLL_PERIOD_MS);
}
}
}
- 1.x
-
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package software.amazon.qldb.tutorial;
import com.amazonaws.services.qldb.AmazonQLDB;
import com.amazonaws.services.qldb.AmazonQLDBClientBuilder;
import com.amazonaws.services.qldb.model.CreateLedgerRequest;
import com.amazonaws.services.qldb.model.CreateLedgerResult;
import com.amazonaws.services.qldb.model.DescribeLedgerResult;
import com.amazonaws.services.qldb.model.LedgerState;
import com.amazonaws.services.qldb.model.PermissionsMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Create a ledger and wait for it to be active.
*
* This code expects that you have AWS credentials setup per:
* http://docs.aws.amazon.com/java-sdk/latest/developer-guide/setup-credentials.html
*/
public final class CreateLedger {
public static final Logger log = LoggerFactory.getLogger(CreateLedger.class);
public static final Long LEDGER_CREATION_POLL_PERIOD_MS = 10_000L;
public static AmazonQLDB client = getClient();
private CreateLedger() { }
/**
* Build a low-level QLDB client.
*
* @return {@link AmazonQLDB} control plane client.
*/
public static AmazonQLDB getClient() {
return AmazonQLDBClientBuilder.standard().build();
}
public static void main(final String... args) throws Exception {
try {
create(Constants.LEDGER_NAME);
waitForActive(Constants.LEDGER_NAME);
} catch (Exception e) {
log.error("Unable to create the ledger!", e);
throw e;
}
}
/**
* Create a new ledger with the specified ledger name.
*
* @param ledgerName
* Name of the ledger to be created.
* @return {@link CreateLedgerResult} from QLDB.
*/
public static CreateLedgerResult create(final String ledgerName) {
log.info("Let's create the ledger with name: {}...", ledgerName);
CreateLedgerRequest request = new CreateLedgerRequest()
.withName(ledgerName)
.withPermissionsMode(PermissionsMode.ALLOW_ALL);
CreateLedgerResult result = client.createLedger(request);
log.info("Success. Ledger state: {}.", result.getState());
return result;
}
/**
* Wait for a newly created ledger to become active.
*
* @param ledgerName
* Name of the ledger to wait on.
* @return {@link DescribeLedgerResult} from QLDB.
* @throws InterruptedException if thread is being interrupted.
*/
public static DescribeLedgerResult waitForActive(final String ledgerName) throws InterruptedException {
log.info("Waiting for ledger to become active...");
while (true) {
DescribeLedgerResult result = DescribeLedger.describe(ledgerName);
if (result.getState().equals(LedgerState.ACTIVE.name())) {
log.info("Success. Ledger is active and ready to use.");
return result;
}
log.info("The ledger is still creating. Please wait...");
Thread.sleep(LEDGER_CREATION_POLL_PERIOD_MS);
}
}
}
-
createLedger
호출 시 원장 이름과 권한 모드를 지정해야 합니다. 원장 데이터의 보안을 극대화하려면 STANDARD
권한 모드를 사용할 것을 권장합니다.
-
원장을 생성할 때 기본적으로 삭제 방지가 활성화됩니다. 이는 사용자가 원장을 삭제하는 QLDB 것을 방지하는 기능입니다. QLDBAPI또는 () 를 사용하여 원장 생성 시 삭제 보호를 비활성화할 수 있습니다. AWS Command Line Interface AWS CLI
-
선택적으로, 원장에 첨부할 태그를 지정할 수도 있습니다.
새 원장과의 연결을 확인하려면 2단계: 원장과의 연결을 테스트로 이동하세요.