-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure Compliance with AIP Rules for Resource Creation and Update (#1025
) Motivation: Identified violations of two AIP (API Improvement Proposals) rules: - CREATE: If a user tries to create a resource with an ID that would result in a duplicate resource name, the service must return an ALREADY_EXISTS error. - UPDATE: If the method call is on a resource that already exists and all fields match, the existing resource should be returned unchanged. Modifications: - Implemented the aforementioned AIP rules during resource creation and update. - Added `ControlPlaneExceptionHandlerFunction``, which converts exceptions raised within Central Dogma to appropriate gRPC status codes. Result: - The service now correctly returns an ALREADY_EXISTS error for duplicate resource creation attempts. - Resource updates that do not change any fields will now correctly return the existing resource without modification.
- Loading branch information
Showing
13 changed files
with
145 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ain/java/com/linecorp/centraldogma/xds/internal/ControlPlaneExceptionHandlerFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2024 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linecorp.centraldogma.xds.internal; | ||
|
||
import com.linecorp.armeria.common.RequestContext; | ||
import com.linecorp.armeria.common.annotation.Nullable; | ||
import com.linecorp.armeria.common.grpc.GrpcExceptionHandlerFunction; | ||
import com.linecorp.centraldogma.common.RepositoryNotFoundException; | ||
import com.linecorp.centraldogma.common.TooManyRequestsException; | ||
import com.linecorp.centraldogma.server.internal.storage.RequestAlreadyTimedOutException; | ||
import com.linecorp.centraldogma.server.storage.StorageException; | ||
|
||
import io.grpc.Metadata; | ||
import io.grpc.Status; | ||
import io.grpc.Status.Code; | ||
|
||
final class ControlPlaneExceptionHandlerFunction implements GrpcExceptionHandlerFunction { | ||
|
||
@Nullable | ||
@Override | ||
public Status apply(RequestContext ctx, Status status, Throwable cause, Metadata metadata) { | ||
if (status.getCode() != Code.UNKNOWN) { | ||
return status; | ||
} | ||
|
||
if (cause instanceof TooManyRequestsException) { | ||
return Status.RESOURCE_EXHAUSTED.withCause(cause); | ||
} | ||
|
||
if (cause instanceof RequestAlreadyTimedOutException) { | ||
return Status.DEADLINE_EXCEEDED.withCause(cause); | ||
} | ||
|
||
if (cause instanceof RepositoryNotFoundException) { | ||
return Status.NOT_FOUND.withCause(cause); | ||
} | ||
|
||
if (cause instanceof StorageException) { | ||
return Status.INTERNAL.withCause(cause); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters