-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Service Factory + Individual Services' Factory Implementations (#257)
Service Factory + Individual Services' Factory Implementations Because of the early design, architectural decisions of Xinfra Monitor, the KafkaMonitor class enforces individual Xinfra Monitor Services to carry the same set of constructor parameters. This is a large caveat as not all Service classes don't need the identical constructor arguments. This is not enforced the codebase. It is partially and only silently enforced by convention. Unmaintainable code + non-robust code. Non-evolvable code: each Service's constructor implementations aren't allowed to be evolved independently. 3. Change(s) in one Service's constructor absolutely forces the other Services' constructors to also change its parameters, unfortunately. Signed off by : Andrew Choi
- Loading branch information
Andrew Choi
authored
Jun 2, 2020
1 parent
2fc22fd
commit 10045c5
Showing
14 changed files
with
472 additions
and
49 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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/linkedin/kmf/XinfraMonitorConstants.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,30 @@ | ||
/** | ||
* Copyright 2020 LinkedIn Corp. 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. | ||
*/ | ||
|
||
package com.linkedin.kmf; | ||
|
||
/** | ||
* Constant variables in Xinfra Monitor repo. | ||
*/ | ||
public class XinfraMonitorConstants { | ||
|
||
public XinfraMonitorConstants() { | ||
} | ||
|
||
static final String FACTORY = "Factory"; | ||
|
||
static final String CLASS_NAME_CONFIG = "class.name"; | ||
|
||
static final String METRIC_GROUP_NAME = "kafka-monitor"; | ||
|
||
static final String JMX_PREFIX = "kmf"; | ||
|
||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/linkedin/kmf/services/ConsumeServiceFactory.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,39 @@ | ||
/** | ||
* Copyright 2020 LinkedIn Corp. 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. | ||
*/ | ||
|
||
package com.linkedin.kmf.services; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
|
||
/** | ||
* Factory that constructs the ConsumeService. | ||
*/ | ||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
public class ConsumeServiceFactory implements ServiceFactory { | ||
private final Map _props; | ||
private final String _name; | ||
|
||
public ConsumeServiceFactory(Map props, String name) { | ||
_props = props; | ||
_name = name; | ||
} | ||
|
||
@Override | ||
public Service createService() throws Exception { | ||
|
||
CompletableFuture<Void> topicPartitionResult = new CompletableFuture<>(); | ||
topicPartitionResult.complete(null); | ||
ConsumerFactoryImpl consumerFactory = new ConsumerFactoryImpl(_props); | ||
|
||
return new ConsumeService(_name, topicPartitionResult, consumerFactory); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/linkedin/kmf/services/DefaultMetricsReporterServiceFactory.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,35 @@ | ||
/** | ||
* Copyright 2020 LinkedIn Corp. 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. | ||
*/ | ||
|
||
package com.linkedin.kmf.services; | ||
|
||
import java.util.Map; | ||
|
||
|
||
/** | ||
* Factory class which instantiates a DefaultMetricsReporterService. | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class DefaultMetricsReporterServiceFactory implements ServiceFactory { | ||
private final Map _properties; | ||
private final String _serviceName; | ||
|
||
public DefaultMetricsReporterServiceFactory(Map properties, String serviceName) { | ||
|
||
_properties = properties; | ||
_serviceName = serviceName; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public Service createService() throws Exception { | ||
return new DefaultMetricsReporterService(_properties, _serviceName); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/linkedin/kmf/services/GraphiteMetricsReporterServiceFactory.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,36 @@ | ||
/** | ||
* Copyright 2020 LinkedIn Corp. 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. | ||
*/ | ||
|
||
package com.linkedin.kmf.services; | ||
|
||
import java.util.Map; | ||
|
||
|
||
/** | ||
* Factory class which instantiates a GraphiteMetricsReporterServiceFactory service. | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class GraphiteMetricsReporterServiceFactory implements ServiceFactory { | ||
|
||
private final Map _properties; | ||
private final String _serviceName; | ||
|
||
public GraphiteMetricsReporterServiceFactory(Map properties, String serviceName) { | ||
|
||
_properties = properties; | ||
_serviceName = serviceName; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public Service createService() throws Exception { | ||
return new GraphiteMetricsReporterService(_properties, _serviceName); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/linkedin/kmf/services/JolokiaServiceFactory.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,36 @@ | ||
/** | ||
* Copyright 2020 LinkedIn Corp. 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. | ||
*/ | ||
|
||
package com.linkedin.kmf.services; | ||
|
||
import java.util.Map; | ||
|
||
|
||
/** | ||
* Factory class which instantiates a JolokiaService service. | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class JolokiaServiceFactory implements ServiceFactory { | ||
|
||
private final Map _properties; | ||
private final String _serviceName; | ||
|
||
public JolokiaServiceFactory(Map properties, String serviceName) { | ||
|
||
_properties = properties; | ||
_serviceName = serviceName; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public Service createService() throws Exception { | ||
return new JolokiaService(_properties, _serviceName); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/linkedin/kmf/services/KafkaMetricsReporterServiceFactory.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,41 @@ | ||
/** | ||
* Copyright 2020 LinkedIn Corp. 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. | ||
*/ | ||
|
||
package com.linkedin.kmf.services; | ||
|
||
import java.util.Map; | ||
import org.apache.kafka.clients.admin.AdminClient; | ||
|
||
|
||
/** | ||
* Factory class which instantiates a KafkaMetricsReporterService service object. | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class KafkaMetricsReporterServiceFactory implements ServiceFactory { | ||
|
||
private final Map _properties; | ||
private final String _serviceName; | ||
|
||
public KafkaMetricsReporterServiceFactory(Map properties, String serviceName) { | ||
|
||
_properties = properties; | ||
_serviceName = serviceName; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public Service createService() throws Exception { | ||
|
||
AdminClient adminClient = AdminClient.create(_properties); | ||
|
||
return new KafkaMetricsReporterService(_properties, _serviceName, adminClient); | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/linkedin/kmf/services/MultiClusterTopicManagementServiceFactory.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,36 @@ | ||
/** | ||
* Copyright 2020 LinkedIn Corp. 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. | ||
*/ | ||
|
||
package com.linkedin.kmf.services; | ||
|
||
import java.util.Map; | ||
|
||
|
||
/** | ||
* Factory which instantiates a MultiClusterTopicManagementService service object. | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class MultiClusterTopicManagementServiceFactory implements ServiceFactory { | ||
|
||
private final Map _properties; | ||
private final String _serviceName; | ||
|
||
public MultiClusterTopicManagementServiceFactory(Map properties, String serviceName) { | ||
|
||
_properties = properties; | ||
_serviceName = serviceName; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public Service createService() throws Exception { | ||
return new MultiClusterTopicManagementService(_properties, _serviceName); | ||
} | ||
} |
Oops, something went wrong.