Skip to content

Commit 2f49111

Browse files
authored
Implement spi layer for Logging service (#1056)
1 parent a327c64 commit 2f49111

7 files changed

Lines changed: 670 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.logging;
18+
19+
import com.google.cloud.Service;
20+
21+
public interface Logging extends AutoCloseable, Service<LoggingOptions> {
22+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.logging;
18+
19+
import com.google.api.gax.grpc.ApiException;
20+
import com.google.cloud.BaseServiceException;
21+
22+
import java.io.IOException;
23+
import java.util.Set;
24+
25+
/**
26+
* Logging service exception.
27+
*/
28+
public final class LoggingException extends BaseServiceException {
29+
30+
private static final long serialVersionUID = 449689219311927047L;
31+
32+
public LoggingException(IOException ex, boolean idempotent) {
33+
super(ex, idempotent);
34+
}
35+
36+
public LoggingException(ApiException apiException, boolean idempotent) {
37+
super(apiException, idempotent);
38+
}
39+
40+
@Override
41+
protected Set<Error> retryableErrors() {
42+
return null;
43+
}
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.logging;
18+
19+
import com.google.cloud.ServiceFactory;
20+
21+
/**
22+
* An interface for Logging factories.
23+
*/
24+
public interface LoggingFactory extends ServiceFactory<Logging, LoggingOptions> {
25+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.logging;
18+
19+
import com.google.cloud.GrpcServiceOptions;
20+
import com.google.cloud.logging.spi.DefaultLoggingRpc;
21+
import com.google.cloud.logging.spi.LoggingRpc;
22+
import com.google.cloud.logging.spi.LoggingRpcFactory;
23+
import com.google.common.collect.ImmutableSet;
24+
25+
import java.io.IOException;
26+
import java.util.Set;
27+
28+
public class LoggingOptions extends GrpcServiceOptions<Logging, LoggingRpc, LoggingOptions> {
29+
30+
private static final long serialVersionUID = -2996451684945061075L;
31+
private static final String LOGGING_SCOPE = "https://www.googleapis.com/auth/logging.admin";
32+
private static final Set<String> SCOPES = ImmutableSet.of(LOGGING_SCOPE);
33+
private static final String DEFAULT_HOST = "https://logging.googleapis.com";
34+
35+
public static class DefaultLoggingFactory implements LoggingFactory {
36+
private static final LoggingFactory INSTANCE = new DefaultLoggingFactory();
37+
38+
@Override
39+
public Logging create(LoggingOptions options) {
40+
// todo(mziccard) uncomment once LoggingImpl is implemented
41+
// return new LoggingImpl(options);
42+
return null;
43+
}
44+
}
45+
46+
/**
47+
* Returns a default {@code LoggingOptions} instance.
48+
*/
49+
public static LoggingOptions defaultInstance() {
50+
return builder().build();
51+
}
52+
53+
public static class DefaultLoggingRpcFactory implements LoggingRpcFactory {
54+
private static final LoggingRpcFactory INSTANCE = new DefaultLoggingRpcFactory();
55+
56+
@Override
57+
public LoggingRpc create(LoggingOptions options) {
58+
try {
59+
return new DefaultLoggingRpc(options);
60+
} catch (IOException e) {
61+
throw new LoggingException(e, true);
62+
}
63+
}
64+
}
65+
66+
@Override
67+
protected String defaultHost() {
68+
return DEFAULT_HOST;
69+
}
70+
71+
public static class Builder extends
72+
GrpcServiceOptions.Builder<Logging, LoggingRpc, LoggingOptions, Builder> {
73+
74+
private Builder() {}
75+
76+
private Builder(LoggingOptions options) {
77+
super(options);
78+
}
79+
80+
@Override
81+
public LoggingOptions build() {
82+
return new LoggingOptions(this);
83+
}
84+
}
85+
86+
protected LoggingOptions(Builder builder) {
87+
super(LoggingFactory.class, LoggingRpcFactory.class, builder);
88+
}
89+
90+
@Override
91+
protected ExecutorFactory executorFactory() {
92+
return super.executorFactory();
93+
}
94+
95+
@Override
96+
protected LoggingFactory defaultServiceFactory() {
97+
return DefaultLoggingFactory.INSTANCE;
98+
}
99+
100+
@Override
101+
protected LoggingRpcFactory defaultRpcFactory() {
102+
return DefaultLoggingRpcFactory.INSTANCE;
103+
}
104+
105+
@Override
106+
protected Set<String> scopes() {
107+
return SCOPES;
108+
}
109+
110+
@Override
111+
public boolean equals(Object obj) {
112+
return obj instanceof LoggingOptions && baseEquals((LoggingOptions) obj);
113+
}
114+
115+
@Override
116+
public int hashCode() {
117+
return baseHashCode();
118+
}
119+
120+
@SuppressWarnings("unchecked")
121+
@Override
122+
public Builder toBuilder() {
123+
return new Builder(this);
124+
}
125+
126+
public static Builder builder() {
127+
return new Builder();
128+
}
129+
}

0 commit comments

Comments
 (0)