Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release candidate/2024 07 #142

Merged
merged 2 commits into from
Jul 17, 2024
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ nb-configuration.xml
##############################
## OS X
##############################
.DS_Store
.DS_Store

gen
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "codegen/apis"]
path = codegen/apis
url = [email protected]:pinecone-io/apis.git
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ having to obtain the *pinecone-client* dependencies separately.
### Initializing the client

Before you can use the Pinecone Java SDK, you must sign up for a Pinecone account and find your API key in the Pinecone
console
dashboard at [https://app.pinecone.io](https://app.pinecone.io).
console dashboard at [https://app.pinecone.io](https://app.pinecone.io).

#### Using apiKey

Expand Down Expand Up @@ -75,7 +74,7 @@ public class InitializeClientExample {

OkHttpClient httpClient = builder.build();

Pinecone pinecone = new Pinecone.Builder("PINECONE_API_KEY").build();
Pinecone pinecone = new Pinecone.Builder("PINECONE_API_KEY").withOkHttpClient(httpClient).build();
}
}
```
Expand Down
1 change: 1 addition & 0 deletions codegen/apis
Submodule apis added at 3e5739
87 changes: 87 additions & 0 deletions codegen/build-oas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

set -eux -o pipefail

version=$1 # e.g. 2024-07
modules=("control")

destination="src/main/java/org/openapitools"
build_dir="gen"

update_apis_repo() {
echo "Updating apis repo"
pushd codegen/apis
git fetch
git checkout main
git pull
just build
popd
}

verify_spec_version() {
local version=$1
echo "Verifying spec version $version exists in apis repo"
if [ -z "$version" ]; then
echo "Version is required"
exit 1
fi

verify_directory_exists "codegen/apis/_build/${version}"
}

verify_file_exists() {
local filename=$1
if [ ! -f "$filename" ]; then
echo "File does not exist at $filename"
exit 1
fi
}

verify_directory_exists() {
local directory=$1
if [ ! -d "$directory" ]; then
echo "Directory does not exist at $directory"
exit 1
fi
}

generate_client() {
local module_name=$1

oas_file="codegen/apis/_build/${version}/${module_name}_${version}.oas.yaml"

verify_file_exists $oas_file

# Cleanup previous build files
echo "Cleaning up previous build files"
rm -rf "${build_dir}"

# Generate client module
docker run --rm -v $(pwd):/workspace openapitools/openapi-generator-cli:v7.0.1 generate \
--input-spec "/workspace/$oas_file" \
--generator-name java \
--additional-properties=dateLibrary='java8',disallowAdditionalPropertiesIfNotPresent=false \
--output "/workspace/${build_dir}"

# Copy the generated module to the correct location
rm -rf "${destination}/${module_name}"
mkdir -p "${destination}/${module_name}"

path_to_copy="${build_dir}/src/main/java/org/openapitools/client"
cp -r $path_to_copy "${destination}/${module_name}"

# Adjust package names in generated file
find "${destination}/${module_name}" -name "*.java" | while IFS= read -r file; do
sed -i '' "s/org\.openapitools\.client/org\.openapitools\.${module_name}\.client/g" "$file"
done
}

update_apis_repo
verify_spec_version $version

rm -rf "${destination}"
mkdir -p "${destination}"

for module in "${modules[@]}"; do
generate_client $module
done
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.pinecone.clients.Pinecone;
import io.pinecone.exceptions.PineconeException;
import io.pinecone.proto.DescribeIndexStatsResponse;
import org.openapitools.client.model.*;
import org.openapitools.control.client.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -50,8 +50,8 @@ public class TestResourcesManager {
? "us-east4-gcp"
: System.getenv("PINECONE_ENVIRONMENT");
private static final String metric = System.getenv("METRIC") == null
? IndexMetric.DOTPRODUCT.toString()
: IndexMetric.valueOf(System.getenv("METRIC")).toString();
? IndexModel.MetricEnum.DOTPRODUCT.toString()
: IndexModel.MetricEnum.valueOf(System.getenv("METRIC")).toString();
private static final String cloud = System.getenv("CLOUD") == null
? ServerlessSpec.CloudEnum.AWS.toString()
: System.getenv("CLOUD");
Expand Down Expand Up @@ -317,7 +317,7 @@ public String getOrCreateServerlessIndex() throws InterruptedException, Pinecone
String indexName = RandomStringBuilder.build("serverless-index", 8);

serverlessIndexModel = pineconeClient.createServerlessIndex(indexName, metric, dimension, cloud,
region);
region, DeletionProtection.DISABLED);
waitUntilIndexIsReady(pineconeClient, indexName);

// Explicitly wait after ready to avoid the "no healthy upstream" issue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.pinecone.clients.Pinecone;
import io.pinecone.proto.DescribeIndexStatsResponse;
import io.pinecone.proto.NamespaceSummary;
import org.openapitools.client.model.*;
import org.openapitools.control.client.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.*;
import org.openapitools.control.client.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -117,11 +117,11 @@ public void testIndexFromCollectionHappyPath() throws InterruptedException {
public void testCreateIndexFromCollectionWithDiffMetric() throws InterruptedException {
// Use a different metric than the source index
String[] metrics = {
IndexMetric.COSINE.toString(),
IndexMetric.EUCLIDEAN.toString(),
IndexMetric.DOTPRODUCT.toString()
IndexModel.MetricEnum.COSINE.toString(),
IndexModel.MetricEnum.EUCLIDEAN.toString(),
IndexModel.MetricEnum.DOTPRODUCT.toString()
};
String targetMetric = IndexMetric.COSINE.toString();
String targetMetric = IndexModel.MetricEnum.COSINE.toString();
for (String metric : metrics) {
if (!metric.equals(sourceIndexMetric)) {
targetMetric = metric;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.IndexModel;
import org.openapitools.client.model.IndexModelStatus;
import org.openapitools.client.model.PodSpec;
import org.openapitools.control.client.model.DeletionProtection;
import org.openapitools.control.client.model.IndexModel;
import org.openapitools.control.client.model.IndexModelStatus;
import org.openapitools.control.client.model.PodSpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -55,7 +56,7 @@ public void afterEach() throws InterruptedException {
@Test
public void configureIndexWithInvalidIndexName() {
try {
controlPlaneClient.configureIndex("non-existent-index", 3);
controlPlaneClient.configurePodsIndex("non-existent-index", 3, DeletionProtection.DISABLED);

fail("Expected to throw PineconeNotFoundException");
} catch (PineconeNotFoundException expected) {
Expand All @@ -66,7 +67,7 @@ public void configureIndexWithInvalidIndexName() {
@Test
public void configureIndexExceedingQuota() {
try {
controlPlaneClient.configureIndex(indexName, 600);
controlPlaneClient.configurePodsIndex(indexName, 30, DeletionProtection.DISABLED);
fail("Expected to throw PineconeForbiddenException");
} catch (PineconeForbiddenException expected) {
assertTrue(expected.getLocalizedMessage().contains("reached the max pods allowed"));
Expand All @@ -81,7 +82,7 @@ public void scaleUpAndDown() throws InterruptedException {

// Verify the scaled up replicas
assertWithRetry(() -> {
controlPlaneClient.configureIndex(indexName, 3);
controlPlaneClient.configurePodsIndex(indexName, 3, DeletionProtection.DISABLED);
PodSpec podSpec = controlPlaneClient.describeIndex(indexName).getSpec().getPod();
assertNotNull(podSpec);
assertEquals(podSpec.getReplicas(), 3);
Expand All @@ -91,7 +92,7 @@ public void scaleUpAndDown() throws InterruptedException {

// Verify replicas were scaled down
assertWithRetry(() -> {
controlPlaneClient.configureIndex(indexName, 1);
controlPlaneClient.configurePodsIndex(indexName, 1, DeletionProtection.DISABLED);
PodSpec podSpec = controlPlaneClient.describeIndex(indexName).getSpec().getPod();
assertNotNull(podSpec);
assertEquals(podSpec.getReplicas(), 1);
Expand All @@ -107,7 +108,7 @@ public void changingBasePodType() throws InterruptedException {
assertEquals(1, indexModel.getSpec().getPod().getReplicas());

// Try to change the base pod type
controlPlaneClient.configureIndex(indexName, "p2.x2");
controlPlaneClient.configurePodsIndex(indexName, "p2.x2");

fail("Expected to throw PineconeBadRequestException");
} catch (PineconeBadRequestException expected) {
Expand All @@ -125,7 +126,7 @@ public void sizeIncrease() throws InterruptedException {
// Change the pod type to a larger one
// Get the index description to verify the new pod type
assertWithRetry(() -> {
controlPlaneClient.configureIndex(indexName, "p1.x2");
controlPlaneClient.configurePodsIndex(indexName, "p1.x2");
PodSpec podSpec = controlPlaneClient.describeIndex(indexName).getSpec().getPod();
assertNotNull(podSpec);
assertEquals(podSpec.getPodType(), "p1.x2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.pinecone.helpers.TestResourcesManager;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.*;
import org.openapitools.control.client.model.*;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -36,7 +36,7 @@ public void describeAndListIndex() {
assertNotNull(indexModel);
assertEquals(indexDimension, indexModel.getDimension());
assertEquals(indexName, indexModel.getName());
assertEquals(IndexMetric.DOTPRODUCT, indexModel.getMetric());
assertEquals(IndexModel.MetricEnum.DOTPRODUCT, indexModel.getMetric());
assertNotNull(indexModel.getSpec().getPod());
assertEquals(indexPodType, indexModel.getSpec().getPod().getPodType());

Expand All @@ -63,7 +63,7 @@ public void createPodsIndexWithMinimumRequiredParams() {
assertEquals(podType, podsIndex.getSpec().getPod().getPodType());

// Confirm defaults are put in by the backend when not supplied by the user
assertEquals(IndexMetric.COSINE, podsIndex.getMetric());
assertEquals(IndexModel.MetricEnum.COSINE, podsIndex.getMetric());
assertEquals(1, podsIndex.getSpec().getPod().getPods());
assertEquals(1, podsIndex.getSpec().getPod().getReplicas());
assertEquals(1, podsIndex.getSpec().getPod().getShards());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.pinecone.integration.controlPlane.pod;

import io.pinecone.clients.Pinecone;
import io.pinecone.helpers.RandomStringBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openapitools.control.client.model.DeletionProtection;
import org.openapitools.control.client.model.IndexModel;

public class DeletionProtectionTest {
private static final Pinecone controlPlaneClient = new Pinecone
.Builder(System.getenv("PINECONE_API_KEY"))
.withSourceTag("pinecone_test")
.build();

@Test
public void createPodIndexWithDeletionProtectionEnabled() {
String indexName = RandomStringBuilder.build("create-pod", 8);
// Create pod index with deletion protection enabled
controlPlaneClient.createPodsIndex(indexName, 3, "us-east-1-aws", "p1.x1", DeletionProtection.ENABLED);
IndexModel indexModel = controlPlaneClient.describeIndex(indexName);
DeletionProtection deletionProtection = indexModel.getDeletionProtection();
Assertions.assertEquals(deletionProtection, DeletionProtection.ENABLED);
// Configure index to disable deletionProtection
controlPlaneClient.configurePodsIndex(indexName, DeletionProtection.DISABLED);
// Delete index
controlPlaneClient.deleteIndex(indexName);
}

@Test
public void createPodIndexWithDeletionProtectionDisabled() {
String indexName = RandomStringBuilder.build("create-pod", 8);
// Create pod index with deletion protection disabled
controlPlaneClient.createPodsIndex(indexName, 3, "us-east-1-aws", "p1.x1");
IndexModel indexModel = controlPlaneClient.describeIndex(indexName);
DeletionProtection deletionProtection = indexModel.getDeletionProtection();
Assertions.assertEquals(deletionProtection, DeletionProtection.DISABLED);
// Configure index to enable deletionProtection
controlPlaneClient.configurePodsIndex(indexName, DeletionProtection.ENABLED);
indexModel = controlPlaneClient.describeIndex(indexName);
deletionProtection = indexModel.getDeletionProtection();
Assertions.assertEquals(deletionProtection, DeletionProtection.ENABLED);
// Configure index to disable deletionProtection
controlPlaneClient.configurePodsIndex(indexName, DeletionProtection.DISABLED);
// Delete index
controlPlaneClient.deleteIndex(indexName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.pinecone.helpers.TestResourcesManager;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openapitools.client.model.*;
import org.openapitools.control.client.model.*;

import java.util.Arrays;

Expand Down Expand Up @@ -36,7 +36,7 @@ public void describeAndListIndex() {
assertNotNull(indexModel);
assertEquals(dimension, indexModel.getDimension());
assertEquals(indexName, indexModel.getName());
assertEquals(IndexMetric.DOTPRODUCT, indexModel.getMetric());
assertEquals(IndexModel.MetricEnum.DOTPRODUCT, indexModel.getMetric());
assertNotNull(indexModel.getSpec().getServerless());

// List the index
Expand All @@ -48,7 +48,7 @@ public void describeAndListIndex() {
@Test
public void createServerlessIndexWithInvalidName() {
try {
controlPlaneClient.createServerlessIndex("Invalid-name", "cosine", 3, "aws", "us-west-2");
controlPlaneClient.createServerlessIndex("Invalid-name", "cosine", 3, "aws", "us-west-2", DeletionProtection.DISABLED);

fail("Expected to throw PineconeBadRequestException");
} catch (PineconeBadRequestException expected) {
Expand All @@ -59,7 +59,7 @@ public void createServerlessIndexWithInvalidName() {
@Test
public void createServerlessIndexWithInvalidDimension() {
try {
controlPlaneClient.createServerlessIndex("serverless-test-index", "cosine", -3, "aws", "us-west-2");
controlPlaneClient.createServerlessIndex("serverless-test-index", "cosine", -3, "aws", "us-west-2", DeletionProtection.DISABLED);
fail("Expected to throw PineconeValidationException");
} catch (PineconeValidationException expected) {
assertTrue(expected.getLocalizedMessage().contains("Dimension must be greater than 0"));
Expand All @@ -69,7 +69,7 @@ public void createServerlessIndexWithInvalidDimension() {
@Test
public void createServerlessIndexWithInvalidCloud() {
try {
controlPlaneClient.createServerlessIndex("serverless-test-index", "cosine", 3, "blah", "us-west-2");
controlPlaneClient.createServerlessIndex("serverless-test-index", "cosine", 3, "blah", "us-west-2", DeletionProtection.DISABLED);
fail("Expected to throw PineconeValidationException");
} catch (PineconeValidationException expected) {
assertTrue(expected.getLocalizedMessage().contains("Cloud cannot be null or empty. Must be one of " + Arrays.toString(ServerlessSpec.CloudEnum.values())));
Expand All @@ -79,7 +79,7 @@ public void createServerlessIndexWithInvalidCloud() {
@Test
public void createServerlessIndexWithInvalidRegion() {
try {
controlPlaneClient.createServerlessIndex("serverless-test-index", "cosine", 3, "aws", "invalid-region");
controlPlaneClient.createServerlessIndex("serverless-test-index", "cosine", 3, "aws", "invalid-region", DeletionProtection.DISABLED);
fail("Expected to throw PineconeNotFoundException");
} catch (PineconeNotFoundException expected) {
assertTrue(expected.getLocalizedMessage().contains("Resource cloud: aws region: invalid-region not found"));
Expand Down
Loading
Loading