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

Auto format to Google style with Spotless #317

Merged
merged 3 commits into from
Nov 28, 2019
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
18 changes: 15 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,23 @@ Please submit a **pull request** to initiate the code review process. We use [pr

### Java

We conform to the [java google style guide](https://google.github.io/styleguide/javaguide.html)
We conform to the [Google Java Style Guide]. Maven can helpfully take care of
that for you before you commit:

If using Intellij please import the code styles:
https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml
$ mvn spotless:apply

Formatting will be checked automatically during the `verify` phase. This can be
skipped temporarily:

$ mvn spotless:check # Check is automatic upon `mvn verify`
$ mvn verify -Dspotless.check.skip

If you're using IntelliJ, you can import [these code style settings][G
IntelliJ] if you'd like to use the IDE's reformat function as you work.

### Go

Make sure you apply `go fmt`.

[Google Java Style Guide]: https://google.github.io/styleguide/javaguide.html
[G IntelliJ]: https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml
7 changes: 3 additions & 4 deletions core/src/main/java/feast/core/CoreApplication.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2018 The Feast Authors
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -12,9 +13,7 @@
* 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 feast.core;

import feast.core.config.FeastProperties;
Expand All @@ -34,4 +33,4 @@ public class CoreApplication {
public static void main(String[] args) {
SpringApplication.run(CoreApplication.class, args);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* 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
*
* 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 feast.core.config;

import io.grpc.ServerBuilder;
Expand All @@ -8,7 +24,7 @@
@Component
public class CoreGRpcServerBuilderConfig extends GRpcServerBuilderConfigurer {
@Override
public void configure(ServerBuilder<?> serverBuilder){
public void configure(ServerBuilder<?> serverBuilder) {
serverBuilder.addService(ProtoReflectionService.newInstance());
}
}
19 changes: 16 additions & 3 deletions core/src/main/java/feast/core/config/FeastProperties.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* 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
*
* 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 feast.core.config;

import java.util.Map;
Expand Down Expand Up @@ -41,6 +57,3 @@ public static class MetricsProperties {
private int port;
}
}



43 changes: 32 additions & 11 deletions core/src/main/java/feast/core/config/FeatureStreamConfig.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* 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
*
* 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 feast.core.config;

import com.google.common.base.Strings;
Expand Down Expand Up @@ -27,8 +43,7 @@ public class FeatureStreamConfig {
@Bean
public Source getDefaultSource(FeastProperties feastProperties) {
StreamProperties streamProperties = feastProperties.getStream();
SourceType featureStreamType = SourceType
.valueOf(streamProperties.getType().toUpperCase());
SourceType featureStreamType = SourceType.valueOf(streamProperties.getType().toUpperCase());
switch (featureStreamType) {
case KAFKA:
String bootstrapServers = streamProperties.getOptions().get("bootstrapServers");
Expand All @@ -38,25 +53,31 @@ public Source getDefaultSource(FeastProperties feastProperties) {
map.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "1000");
AdminClient client = AdminClient.create(map);

NewTopic newTopic = new NewTopic(topicName,
Integer.valueOf(streamProperties.getOptions().getOrDefault("numPartitions", "1")),
Short.valueOf(streamProperties.getOptions().getOrDefault("replicationFactor", "1")));
CreateTopicsResult createTopicsResult = client
.createTopics(Collections.singleton(newTopic));
NewTopic newTopic =
new NewTopic(
topicName,
Integer.valueOf(streamProperties.getOptions().getOrDefault("numPartitions", "1")),
Short.valueOf(
streamProperties.getOptions().getOrDefault("replicationFactor", "1")));
CreateTopicsResult createTopicsResult =
client.createTopics(Collections.singleton(newTopic));
try {
createTopicsResult.values().get(topicName).get();
} catch (InterruptedException | ExecutionException e) {
if (e.getCause().getClass().equals(TopicExistsException.class)) {
log.warn(Strings
.lenientFormat(
log.warn(
Strings.lenientFormat(
"Unable to create topic %s in the feature stream, topic already exists, using existing topic.",
topicName));
} else {
throw new RuntimeException(e.getMessage(), e);
}
}
KafkaSourceConfig sourceConfig = KafkaSourceConfig.newBuilder()
.setBootstrapServers(bootstrapServers).setTopic(topicName).build();
KafkaSourceConfig sourceConfig =
KafkaSourceConfig.newBuilder()
.setBootstrapServers(bootstrapServers)
.setTopic(topicName)
.build();
return new Source(featureStreamType, sourceConfig, true);
default:
throw new RuntimeException("Unsupported source stream, only [KAFKA] is supported");
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/feast/core/config/JPAConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2018 The Feast Authors
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -12,19 +13,16 @@
* 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 feast.core.config;

import javax.persistence.EntityManagerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

import javax.persistence.EntityManagerFactory;

/** Configuration of JPA related services and beans for the core application. */
@Configuration
@Slf4j
Expand Down
33 changes: 11 additions & 22 deletions core/src/main/java/feast/core/config/JobConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2018 The Feast Authors
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -12,9 +13,7 @@
* 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 feast.core.config;

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
Expand Down Expand Up @@ -42,9 +41,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Beans for job management
*/
/** Beans for job management */
@Slf4j
@Configuration
public class JobConfig {
Expand All @@ -57,9 +54,7 @@ public class JobConfig {
@Bean
@Autowired
public JobManager getJobManager(
FeastProperties feastProperties,
DirectJobRegistry directJobRegistry)
throws Exception {
FeastProperties feastProperties, DirectJobRegistry directJobRegistry) throws Exception {

JobProperties jobProperties = feastProperties.getJobs();
Runner runner = Runner.fromString(jobProperties.getRunner());
Expand Down Expand Up @@ -95,21 +90,17 @@ public JobManager getJobManager(
throw new IllegalStateException("Unable to initialize DataflowJobManager", e);
}
case DIRECT:
return new DirectRunnerJobManager(jobProperties.getOptions(), directJobRegistry,
jobProperties.getMetrics());
return new DirectRunnerJobManager(
jobProperties.getOptions(), directJobRegistry, jobProperties.getMetrics());
default:
throw new IllegalArgumentException("Unsupported runner: " + jobProperties.getRunner());
}
}

/**
* Get a Job Monitor given the runner type and dataflow configuration.
*/
/** Get a Job Monitor given the runner type and dataflow configuration. */
@Bean
public JobMonitor getJobMonitor(
FeastProperties feastProperties,
DirectJobRegistry directJobRegistry)
throws Exception {
FeastProperties feastProperties, DirectJobRegistry directJobRegistry) throws Exception {

JobProperties jobProperties = feastProperties.getJobs();
Runner runner = Runner.fromString(jobProperties.getRunner());
Expand All @@ -132,8 +123,8 @@ public JobMonitor getJobMonitor(
JacksonFactory.getDefaultInstance(),
credential);

return new DataflowJobMonitor(dataflow, jobOptions.get("project"),
jobOptions.get("region"));
return new DataflowJobMonitor(
dataflow, jobOptions.get("project"), jobOptions.get("region"));
} catch (IOException e) {
log.error(
"Unable to find credential required for Dataflow monitoring API: {}", e.getMessage());
Expand All @@ -149,9 +140,7 @@ public JobMonitor getJobMonitor(
}
}

/**
* Get a direct job registry
*/
/** Get a direct job registry */
@Bean
public DirectJobRegistry directJobRegistry() {
return new DirectJobRegistry();
Expand Down
17 changes: 6 additions & 11 deletions core/src/main/java/feast/core/config/WebMvcConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2018 The Feast Authors
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -12,36 +13,30 @@
* 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 feast.core.config;

import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.protobuf.ProtobufJsonFormatHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
* Configuration for the spring web MVC layer
*/
/** Configuration for the spring web MVC layer */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
/**
* Get a json-protobuf converter.
*
* @return ProtobufJsonFormatHttpMessageConverter
*/
@Bean
ProtobufJsonFormatHttpMessageConverter getProtobufHttpMessageConverter() {
return new ProtobufJsonFormatHttpMessageConverter();
}

/**
* Register json-protobuf converter.
*/
/** Register json-protobuf converter. */
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(getProtobufHttpMessageConverter());
Expand Down
20 changes: 18 additions & 2 deletions core/src/main/java/feast/core/dao/FeatureSetRepository.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* 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
*
* 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 feast.core.dao;

import feast.core.model.FeatureSet;
Expand All @@ -6,7 +22,7 @@
import org.springframework.data.jpa.repository.Query;

/** JPA repository supplying FeatureSet objects keyed by id. */
public interface FeatureSetRepository extends JpaRepository<FeatureSet, String> {
public interface FeatureSetRepository extends JpaRepository<FeatureSet, String> {

// Find feature set by name and version
FeatureSet findFeatureSetByNameAndVersion(String name, Integer version);
Expand All @@ -18,6 +34,6 @@ public interface FeatureSetRepository extends JpaRepository<FeatureSet, String>
List<FeatureSet> findByName(String name);

// find all versions of featureSets with names matching the regex
@Query(nativeQuery=true, value="SELECT * FROM feature_sets WHERE name LIKE ?1")
@Query(nativeQuery = true, value = "SELECT * FROM feature_sets WHERE name LIKE ?1")
List<FeatureSet> findByNameWithWildcard(String name);
}
Loading