Skip to content

Commit

Permalink
Implement spi layer for Logging service (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard authored Jun 15, 2016
1 parent a327c64 commit 2f49111
Show file tree
Hide file tree
Showing 7 changed files with 670 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed 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
*
* http://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.google.cloud.logging;

import com.google.cloud.Service;

public interface Logging extends AutoCloseable, Service<LoggingOptions> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed 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
*
* http://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.google.cloud.logging;

import com.google.api.gax.grpc.ApiException;
import com.google.cloud.BaseServiceException;

import java.io.IOException;
import java.util.Set;

/**
* Logging service exception.
*/
public final class LoggingException extends BaseServiceException {

private static final long serialVersionUID = 449689219311927047L;

public LoggingException(IOException ex, boolean idempotent) {
super(ex, idempotent);
}

public LoggingException(ApiException apiException, boolean idempotent) {
super(apiException, idempotent);
}

@Override
protected Set<Error> retryableErrors() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed 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
*
* http://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.google.cloud.logging;

import com.google.cloud.ServiceFactory;

/**
* An interface for Logging factories.
*/
public interface LoggingFactory extends ServiceFactory<Logging, LoggingOptions> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed 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
*
* http://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.google.cloud.logging;

import com.google.cloud.GrpcServiceOptions;
import com.google.cloud.logging.spi.DefaultLoggingRpc;
import com.google.cloud.logging.spi.LoggingRpc;
import com.google.cloud.logging.spi.LoggingRpcFactory;
import com.google.common.collect.ImmutableSet;

import java.io.IOException;
import java.util.Set;

public class LoggingOptions extends GrpcServiceOptions<Logging, LoggingRpc, LoggingOptions> {

private static final long serialVersionUID = -2996451684945061075L;
private static final String LOGGING_SCOPE = "https://www.googleapis.com/auth/logging.admin";
private static final Set<String> SCOPES = ImmutableSet.of(LOGGING_SCOPE);
private static final String DEFAULT_HOST = "https://logging.googleapis.com";

public static class DefaultLoggingFactory implements LoggingFactory {
private static final LoggingFactory INSTANCE = new DefaultLoggingFactory();

@Override
public Logging create(LoggingOptions options) {
// todo(mziccard) uncomment once LoggingImpl is implemented
// return new LoggingImpl(options);
return null;
}
}

/**
* Returns a default {@code LoggingOptions} instance.
*/
public static LoggingOptions defaultInstance() {
return builder().build();
}

public static class DefaultLoggingRpcFactory implements LoggingRpcFactory {
private static final LoggingRpcFactory INSTANCE = new DefaultLoggingRpcFactory();

@Override
public LoggingRpc create(LoggingOptions options) {
try {
return new DefaultLoggingRpc(options);
} catch (IOException e) {
throw new LoggingException(e, true);
}
}
}

@Override
protected String defaultHost() {
return DEFAULT_HOST;
}

public static class Builder extends
GrpcServiceOptions.Builder<Logging, LoggingRpc, LoggingOptions, Builder> {

private Builder() {}

private Builder(LoggingOptions options) {
super(options);
}

@Override
public LoggingOptions build() {
return new LoggingOptions(this);
}
}

protected LoggingOptions(Builder builder) {
super(LoggingFactory.class, LoggingRpcFactory.class, builder);
}

@Override
protected ExecutorFactory executorFactory() {
return super.executorFactory();
}

@Override
protected LoggingFactory defaultServiceFactory() {
return DefaultLoggingFactory.INSTANCE;
}

@Override
protected LoggingRpcFactory defaultRpcFactory() {
return DefaultLoggingRpcFactory.INSTANCE;
}

@Override
protected Set<String> scopes() {
return SCOPES;
}

@Override
public boolean equals(Object obj) {
return obj instanceof LoggingOptions && baseEquals((LoggingOptions) obj);
}

@Override
public int hashCode() {
return baseHashCode();
}

@SuppressWarnings("unchecked")
@Override
public Builder toBuilder() {
return new Builder(this);
}

public static Builder builder() {
return new Builder();
}
}
Loading

0 comments on commit 2f49111

Please sign in to comment.