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

SAMZA-1788: Add LocationIdProvider abstraction. #585

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions samza-api/src/main/java/org/apache/samza/runtime/LocationId.java
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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
*
* 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 org.apache.samza.runtime;

import java.util.Objects;

/**
* Represents the physical execution environment of the StreamProcessor.
* All the stream processors which run from a LocationId should be able to share (read/write)
* their local state stores.
*/
public class LocationId {
private final String locationId;

public LocationId(String locationId) {
if (locationId == null) {
throw new IllegalArgumentException("LocationId cannot be null");
}
this.locationId = locationId;
}

public String getId() {
return this.locationId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LocationId that = (LocationId) o;

return Objects.equals(locationId, that.locationId);
}

@Override
public int hashCode() {
return locationId.hashCode();
}

@Override
public String toString() {
return locationId;
}
}
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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
*
* 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 org.apache.samza.runtime;

/**
* Generates {@link LocationId} that uniquely identifies the
* execution environment of a stream processor.
*/
public interface LocationIdProvider {

LocationId getLocationId();
}
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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
*
* 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 org.apache.samza.runtime;

import org.apache.samza.config.Config;

/**
* Builds the {@link LocationIdProvider}.
*/
public interface LocationIdProviderFactory {
LocationIdProvider getLocationIdProvider(Config config);
}
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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
*
* 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 org.apache.samza.runtime;

import org.apache.samza.config.Config;
import org.apache.samza.util.Util;

/**
* Uses the address of the local host for generating {@link LocationId}.
*/
public class DefaultLocationIdProviderFactory implements LocationIdProviderFactory {
@Override
public LocationIdProvider getLocationIdProvider(Config config) {
return () -> new LocationId(Util.getLocalHost().getHostName());
}
}
Expand Up @@ -23,6 +23,7 @@ package org.apache.samza.config
import java.io.File

import org.apache.samza.container.grouper.stream.GroupByPartitionFactory
import org.apache.samza.runtime.DefaultLocationIdProviderFactory
import org.apache.samza.util.Logging

object JobConfig {
Expand Down Expand Up @@ -77,6 +78,8 @@ object JobConfig {
val DEFAULT_MONITOR_PARTITION_CHANGE_FREQUENCY_MS = 300000
val JOB_SECURITY_MANAGER_FACTORY = "job.security.manager.factory"

val LOCATION_ID_PROVIDER_FACTORY = "locationid.provider.factory"

// Processor Config Constants
val PROCESSOR_ID = "processor.id"
val PROCESSOR_LIST = "processor.list"
Expand Down Expand Up @@ -161,6 +164,8 @@ class JobConfig(config: Config) extends ScalaMapConfig(config) with Logging {

def getSystemStreamPartitionGrouperFactory = getOption(JobConfig.SSP_GROUPER_FACTORY).getOrElse(classOf[GroupByPartitionFactory].getCanonicalName)

def getLocationIdProviderFactory = getOption(JobConfig.LOCATION_ID_PROVIDER_FACTORY).getOrElse(classOf[DefaultLocationIdProviderFactory].getCanonicalName)

def getSecurityManagerFactory = getOption(JobConfig.JOB_SECURITY_MANAGER_FACTORY)

def getSSPMatcherClass = getOption(JobConfig.SSP_MATCHER_CLASS)
Expand Down