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

KNOX-2833 - Ozone integration for Apache Knox #672

Merged
merged 6 commits into from
Nov 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.knox.gateway.topology.discovery.cm.model.ozone;

import com.cloudera.api.swagger.client.ApiException;
import com.cloudera.api.swagger.model.ApiConfigList;
import com.cloudera.api.swagger.model.ApiRole;
import com.cloudera.api.swagger.model.ApiService;
import com.cloudera.api.swagger.model.ApiServiceConfig;
import org.apache.knox.gateway.topology.discovery.cm.ServiceModel;
import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGenerator;

import java.util.Locale;

public class OzoneServiceModelGenerator extends AbstractServiceModelGenerator {

public static final String SERVICE = "OZONE";
public static final String SERVICE_TYPE = "OZONE";
public static final String ROLE_TYPE = "OZONE_MANAGER";


static final String SSL_ENABLED = "ssl_enabled";
static final String HTTP_PORT = "ozone.om.http-port";

static final String HTTPS_PORT = "ozone.om.https-port";
@Override
public String getService() {
return SERVICE;
}

@Override
public String getServiceType() {
return SERVICE_TYPE;
}

@Override
public String getRoleType() {
return ROLE_TYPE;
}

@Override
public ServiceModel.Type getModelType() {
return ServiceModel.Type.UI;
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();

boolean sslEnabled = Boolean.parseBoolean(getRoleConfigValue(roleConfig, SSL_ENABLED));
String scheme = sslEnabled ? "https" : "http";

// Role config properties
String httpPort = getRoleConfigValue(roleConfig, HTTP_PORT);
String httpsPort = getRoleConfigValue(roleConfig, HTTPS_PORT);
ServiceModel model = createServiceModel(String.format(Locale.getDefault(), "%s://%s:%s",
scheme, hostname, sslEnabled ? httpsPort : httpPort));
model.addRoleProperty(getRoleType(),SSL_ENABLED, getRoleConfigValue(roleConfig, SSL_ENABLED));
model.addRoleProperty(getRoleType(),HTTP_PORT, httpPort);
model.addRoleProperty(getRoleType(),HTTPS_PORT,httpsPort);
return model;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.knox.gateway.topology.discovery.cm.model.ozone;

import com.cloudera.api.swagger.client.ApiException;
import com.cloudera.api.swagger.model.ApiConfigList;
import com.cloudera.api.swagger.model.ApiRole;
import com.cloudera.api.swagger.model.ApiService;
import com.cloudera.api.swagger.model.ApiServiceConfig;
import org.apache.knox.gateway.topology.discovery.cm.ServiceModel;
import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGenerator;

import java.util.Locale;

public class ReconServiceModelGenerator extends AbstractServiceModelGenerator {

public static final String SERVICE = "OZONE-RECON";
public static final String SERVICE_TYPE = "OZONE";
public static final String ROLE_TYPE = "OZONE_RECON";


static final String SSL_ENABLED = "ssl_enabled";
static final String HTTP_PORT = "ozone.recon.http-port";

static final String HTTPS_PORT = "ozone.recon.https-port";
@Override
public String getService() {
return SERVICE;
}

@Override
public String getServiceType() {
return SERVICE_TYPE;
}

@Override
public String getRoleType() {
return ROLE_TYPE;
}

@Override
public ServiceModel.Type getModelType() {
return ServiceModel.Type.UI;
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();

boolean sslEnabled = Boolean.parseBoolean(getRoleConfigValue(roleConfig, SSL_ENABLED));
String scheme = sslEnabled ? "https" : "http";

// Role config properties
String httpPort = getRoleConfigValue(roleConfig, HTTP_PORT);
String httpsPort = getRoleConfigValue(roleConfig, HTTPS_PORT);
ServiceModel model = createServiceModel(String.format(Locale.getDefault(), "%s://%s:%s",
scheme, hostname, sslEnabled ? httpsPort : httpPort));
model.addRoleProperty(getRoleType(),SSL_ENABLED, getRoleConfigValue(roleConfig, SSL_ENABLED));
model.addRoleProperty(getRoleType(),HTTP_PORT, httpPort);
model.addRoleProperty(getRoleType(),HTTPS_PORT,httpsPort);
return model;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.knox.gateway.topology.discovery.cm.model.ozone;

import com.cloudera.api.swagger.client.ApiException;
import com.cloudera.api.swagger.model.ApiConfigList;
import com.cloudera.api.swagger.model.ApiRole;
import com.cloudera.api.swagger.model.ApiService;
import com.cloudera.api.swagger.model.ApiServiceConfig;
import org.apache.knox.gateway.topology.discovery.cm.ServiceModel;
import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGenerator;

import java.util.Locale;

public class SCMServiceModelGenerator extends AbstractServiceModelGenerator {

public static final String SERVICE = "OZONE-SCM";
public static final String SERVICE_TYPE = "OZONE";
public static final String ROLE_TYPE = "STORAGE_CONTAINER_MANAGER";


static final String SSL_ENABLED = "ssl_enabled";
static final String HTTP_PORT = "ozone.scm.http-port";

static final String HTTPS_PORT = "ozone.scm.https-port";
@Override
public String getService() {
return SERVICE;
}

@Override
public String getServiceType() {
return SERVICE_TYPE;
}

@Override
public String getRoleType() {
return ROLE_TYPE;
}

@Override
public ServiceModel.Type getModelType() {
return ServiceModel.Type.UI;
}

@Override
public ServiceModel generateService(ApiService service,
ApiServiceConfig serviceConfig,
ApiRole role,
ApiConfigList roleConfig) throws ApiException {
String hostname = role.getHostRef().getHostname();

boolean sslEnabled = Boolean.parseBoolean(getRoleConfigValue(roleConfig, SSL_ENABLED));
String scheme = sslEnabled ? "https" : "http";

// Role config properties
String httpPort = getRoleConfigValue(roleConfig, HTTP_PORT);
String httpsPort = getRoleConfigValue(roleConfig, HTTPS_PORT);
ServiceModel model = createServiceModel(String.format(Locale.getDefault(), "%s://%s:%s",
scheme, hostname, sslEnabled ? httpsPort : httpPort));
model.addRoleProperty(getRoleType(),SSL_ENABLED, getRoleConfigValue(roleConfig, SSL_ENABLED));
model.addRoleProperty(getRoleType(),HTTP_PORT,httpPort);
model.addRoleProperty(getRoleType(),HTTPS_PORT,httpsPort);
return model;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ org.apache.knox.gateway.topology.discovery.cm.model.nifi.NifiServiceModelGenerat
org.apache.knox.gateway.topology.discovery.cm.model.nifi.NifiRegistryServiceModelGenerator
org.apache.knox.gateway.topology.discovery.cm.model.cm.ClouderaManagerAPIServiceModelGenerator
org.apache.knox.gateway.topology.discovery.cm.model.cm.ClouderaManagerUIServiceModelGenerator
org.apache.knox.gateway.topology.discovery.cm.model.ozone.OzoneServiceModelGenerator
org.apache.knox.gateway.topology.discovery.cm.model.ozone.ReconServiceModelGenerator
org.apache.knox.gateway.topology.discovery.cm.model.ozone.SCMServiceModelGenerator


Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.knox.gateway.topology.discovery.cm.model.ozone;

import org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator;
import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGeneratorTest;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class OzoneServiceModelGeneratorTest extends AbstractServiceModelGeneratorTest {

@Test
public void testServiceModelMetadata() {
final Map<String, String> serviceConfig = Collections.emptyMap();
final Map<String, String> roleConfig = new HashMap<>();
roleConfig.put(OzoneServiceModelGenerator.SSL_ENABLED, "true");
roleConfig.put(OzoneServiceModelGenerator.HTTP_PORT, "9874");
roleConfig.put(OzoneServiceModelGenerator.HTTPS_PORT, "9875");
validateServiceModel(createServiceModel(serviceConfig, roleConfig), serviceConfig, roleConfig);
}

@Override
protected String getServiceType() {
return OzoneServiceModelGenerator.SERVICE_TYPE;
}

@Override
protected String getRoleType() {
return OzoneServiceModelGenerator.ROLE_TYPE;
}

@Override
protected ServiceModelGenerator newGenerator() {
return new OzoneServiceModelGenerator();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.knox.gateway.topology.discovery.cm.model.ozone;

import org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator;
import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGeneratorTest;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class ReconServiceModelGeneratorTest extends AbstractServiceModelGeneratorTest {

@Test
public void testServiceModelMetadata() {
final Map<String, String> serviceConfig = Collections.emptyMap();
final Map<String, String> roleConfig = new HashMap<>();
roleConfig.put(ReconServiceModelGenerator.SSL_ENABLED, "true");
roleConfig.put(ReconServiceModelGenerator.HTTP_PORT, "9888");
roleConfig.put(ReconServiceModelGenerator.HTTPS_PORT, "9889");
validateServiceModel(createServiceModel(serviceConfig, roleConfig), serviceConfig, roleConfig);
}

@Override
protected String getServiceType() {
return ReconServiceModelGenerator.SERVICE_TYPE;
}

@Override
protected String getRoleType() {
return ReconServiceModelGenerator.ROLE_TYPE;
}

@Override
protected ServiceModelGenerator newGenerator() {
return new ReconServiceModelGenerator();
}

}