Skip to content

Commit

Permalink
#154 (#154 (comment)): first basic implementation (#155)
Browse files Browse the repository at this point in the history
* #154 (#154 (comment)): first basic implementation

* #110 (comment)

* #154: added management in KNetPS and updated management in KNetCore, removed not complete switch arguments
  • Loading branch information
masesdevelopers authored Nov 27, 2022
1 parent 6d2d563 commit eb9cd9b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 46 deletions.
9 changes: 5 additions & 4 deletions src/net/Documentation/articles/commandlineswitch.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ _knet_ accepts the following command-line switches:
* VerifiableConsumer
* VerifiableProducer
* Connect scope:
* ConnectDistributed
* ConnectStandalone
* ConnectDistributed: moved to KNetConnect (see [KNetConnect](usageConnect.md))
* ConnectStandalone: moved to KNetConnect (see [KNetConnect](usageConnect.md))
* MirrorMaker2
* **KafkaLocation**: represents the path to the root folder of Apache Kafka binary distribution; default value consider that KNetCLI uses the Apache Kafka jars available under the jars folder prepared from the package;
* **ScalaVersion**: the scala version to be used. The default version (_2.13.6_) is binded to the deafult Apache Kafka version available in the package;
* **Log4JConfiguration**: the log4j configuration file; the default uses the file within the package.
* **LogPath**: the path where the logs are stored
* **Log4JConfiguration**: the log4j configuration file; the default uses the file within the package;
* **LogPath**: the path where the logs are stored;
* **DisableJMX**: disable JMX, JMX is enabled by default.

Plus it accepts from:
* **JNet**:
Expand Down
69 changes: 32 additions & 37 deletions src/net/Documentation/articles/usagePS.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Here a list of cmdlets which executes well known tasks defined from Apache Kafka
* KafkaJarLocation
* Log4JPath
* LogPath
* DisableJMX
* **New-KObject**: Creates a new JVM object of the class specified in argument using the parameters within command line for constructor. The arguments are:
* Inherited from JnetPS:
* Class
Expand All @@ -115,103 +116,97 @@ Here a list of cmdlets which executes well known tasks defined from Apache Kafka
* **Start-AclCommand**: start AclCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-BrokerApiVersionsCommand**: start AclCommand. The arguments are:
* **Start-BrokerApiVersionsCommand**: start BrokerApiVersionsCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ConfigCommand**: start AclCommand. The arguments are:
* **Start-ConfigCommand**: start ConfigCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ConsumerGroupCommand**: start AclCommand. The arguments are:
* **Start-ConsumerGroupCommand**: start ConsumerGroupCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-DelegationTokenCommand**: start AclCommand. The arguments are:
* **Start-DelegationTokenCommand**: start DelegationTokenCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-DeleteRecordsCommand**: start AclCommand. The arguments are:
* **Start-DeleteRecordsCommand**: start DeleteRecordsCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-FeatureCommand**: start AclCommand. The arguments are:
* **Start-FeatureCommand**: start FeatureCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-LeaderElectionCommand**: start AclCommand. The arguments are:
* **Start-LeaderElectionCommand**: start LeaderElectionCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-LogDirsCommand**: start AclCommand. The arguments are:
* **Start-LogDirsCommand**: start LogDirsCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-MetadataQuorumCommand**: start AclCommand. The arguments are:
* **Start-MetadataQuorumCommand**: start MetadataQuorumCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ReassignPartitionsCommand**: start AclCommand. The arguments are:
* **Start-ReassignPartitionsCommand**: start ReassignPartitionsCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-TopicCommand**: start AclCommand. The arguments are:
* **Start-TopicCommand**: start TopicCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ZkSecurityMigrator**: start AclCommand. The arguments are:
* **Start-ZkSecurityMigrator**: start ZkSecurityMigrator. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-KafkaStart**: start AclCommand. The arguments are:
* **Start-KafkaStart**: start KafkaStart. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ZooKeeperShell**: start AclCommand. The arguments are:
* **Start-ZooKeeperShell**: start ZooKeeperShell. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ZooKeeperStart**: start AclCommand. The arguments are:
* **Start-ZooKeeperStart**: start ZooKeeperStart. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-MetadataShell**: start AclCommand. The arguments are:
* **Start-MetadataShell**: start MetadataShell. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ClusterTool**: start AclCommand. The arguments are:
* **Start-ClusterTool**: start ClusterTool. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ConsoleConsumer**: start AclCommand. The arguments are:
* **Start-ConsoleConsumer**: start ConsoleConsumer. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ConsoleProducer**: start AclCommand. The arguments are:
* **Start-ConsoleProducer**: start ConsoleProducer. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ConsumerPerformance**: start AclCommand. The arguments are:
* **Start-ConsumerPerformance**: start ConsumerPerformance. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-DumpLogSegments**: start AclCommand. The arguments are:
* **Start-DumpLogSegments**: start DumpLogSegments. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-GetOffsetShell**: start AclCommand. The arguments are:
* **Start-GetOffsetShell**: start GetOffsetShell. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-MirrorMaker**: start AclCommand. The arguments are:
* **Start-MirrorMaker**: start MirrorMaker. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ProducerPerformance**: start AclCommand. The arguments are:
* **Start-ProducerPerformance**: start ProducerPerformance. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ReplicaVerificationTool**: start AclCommand. The arguments are:
* **Start-ReplicaVerificationTool**: start ReplicaVerificationTool. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-StorageTool**: start AclCommand. The arguments are:
* **Start-StorageTool**: start StorageTool. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-StreamsResetter**: start AclCommand. The arguments are:
* **Start-StreamsResetter**: start StreamsResetter. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-TransactionsCommand**: start AclCommand. The arguments are:
* **Start-TransactionsCommand**: start TransactionsCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-VerifiableConsumer**: start AclCommand. The arguments are:
* **Start-VerifiableConsumer**: start VerifiableConsumer. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-VerifiableProducer**: start AclCommand. The arguments are:
* **Start-VerifiableProducer**: start VerifiableProducer. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ConnectDistributed**: start AclCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-ConnectStandalone**: start AclCommand. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class
* **Start-MirrorMaker2**: start AclCommand. The arguments are:
* **Start-MirrorMaker2**: start MirrorMaker2. The arguments are:
* All available arguments of Start-KNetPS;
* Arguments: a string containing the arguments accepted from the Java Main-Class

2 changes: 2 additions & 0 deletions src/net/Documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ There are many client libraries written to manage communication with Apache Kafk
### News

* V1.4.4+: From version 1.4.4 there is a new project, named KNetPS, which permits to write PowerShell client scripts for an Apache Kafka cluster and many other things, [here full usage](articles/usagePS.md).
* V1.4.7+: From version 1.4.7 there is a new project, named KNetConnect, to execute Apache Kafka Connect related jobs, [here full usage](src/net/Documentation/articles/usageConnect.md).

## Runtime engine

Expand Down Expand Up @@ -53,6 +54,7 @@ Have a look at the following resources:
* [KNet usage](articles/usage.md)
* [KNet APIs extensibility](articles/API_extensibility.md)
* [KNetCLI usage](articles/usageCLI.md)
* [KNetConnect usage](articles/usageConnect.md)
* [KNet PowerShell usage](articles/usagePS.md)
* [KNet Template usage](articles/usageTemplates.md)
* [How to build from scratch](articles/howtobuild.md)
Expand Down
3 changes: 3 additions & 0 deletions src/net/KNet/InternalConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class CLIParam
public const string KafkaLocation = "KafkaLocation";
public const string Log4JConfiguration = "Log4JConfiguration";
public const string LogPath = "LogPath";
public const string DisableJMX = "DisableJMX";
public const string EnableJMXAuth = "EnableJMXAuth";
public const string EnableJMXSSL = "EnableJMXAuth";
}

/// <summary>
Expand Down
45 changes: 40 additions & 5 deletions src/net/KNet/KNetCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ public override IEnumerable<IArgumentMetadata> CommandLineArguments
Default = Const.DefaultLogPath,
Help = "The path where log will be stored.",
},
new ArgumentMetadata<string>()
{
Name = CLIParam.DisableJMX,
Type = ArgumentType.Single,
Help = "Disable JMX. Default is JMX enabled without security.",
},
/* hide until other arguments will be added
new ArgumentMetadata<string>()
{
Name = CLIParam.EnableJMXAuth,
Type = ArgumentType.Single,
Help = "Enable authenticate on JMX. Default is not enabled",
},
new ArgumentMetadata<string>()
{
Name = CLIParam.EnableJMXSSL,
Type = ArgumentType.Single,
Help = "Enable SSL on JMX. Default is not enabled.",
},
*/
});
return lst;
}
Expand Down Expand Up @@ -281,7 +301,7 @@ protected override string[] ProcessCommandLine()
_log4JPath = ParsedArgs.Get<string>(CLIParam.Log4JConfiguration);
_logPath = ParsedArgs.Get<string>(CLIParam.LogPath);
_scalaVersion = ParsedArgs.Get<string>(CLIParam.ScalaVersion);

_disableJMX = ParsedArgs.Exist(CLIParam.DisableJMX);
return result;
}

Expand Down Expand Up @@ -311,10 +331,15 @@ protected override string[] ProcessCommandLine()
public static string ApplicationLogPath { get; set; }

/// <summary>
/// Sets the global value of root path
/// Sets the global value of scala version
/// </summary>
public static string ApplicationScalaVersion { get; set; }

/// <summary>
/// Sets the global value to disable JMX
/// </summary>
public static bool? ApplicationDisableJMX { get; set; }

string _classToRun;
/// <summary>
/// The class to run in CLI version
Expand Down Expand Up @@ -355,6 +380,12 @@ protected override string[] ProcessCommandLine()
/// </summary>
public virtual string Log4JOpts { get { return string.Format("file:{0}", Path.Combine(JarRootPath, "config", "tools-log4j.properties")); } }

bool _disableJMX;
/// <summary>
/// Disable JMX
/// </summary>
public virtual bool DisableJMX { get { return ApplicationDisableJMX ?? _disableJMX; } }

/// <inheritdoc cref="JNetCore{T}.PerformanceOptions"/>
protected override IList<string> PerformanceOptions
{
Expand Down Expand Up @@ -382,14 +413,18 @@ protected override IDictionary<string, string> Options

IDictionary<string, string> options = new Dictionary<string, string>(base.Options)
{
{ "-Dcom.sun.management.jmxremote", null },
{ "com.sun.management.jmxremote.authenticate", "false" },
{ "com.sun.management.jmxremote.ssl", "false" },
{ "log4j.configuration", string.IsNullOrEmpty(Log4JPath) ? ((JarRootPath == Const.DefaultRootPath) ? Log4JOpts : null) : $"file:{Log4JPath}"},
{ "kafka.logs.dir", LogDir},
{ "java.awt.headless", "true" },
};

if (!_disableJMX)
{
options.Add("-Dcom.sun.management.jmxremote", null);
options.Add("com.sun.management.jmxremote.authenticate", ParsedArgs.Exist(CLIParam.EnableJMXAuth) ? "true" : "false");
options.Add("com.sun.management.jmxremote.ssl", ParsedArgs.Exist(CLIParam.EnableJMXSSL) ? "true" : "false");
}

return options;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/net/KNetPS/Cmdlet/StartKNetPSCmdletCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ public class StartKNetPSCmdletCommandBase<TCmdlet> : StartJNetPSCmdletCommandBas
HelpMessage = "The path where log will be stored.")]
public string LogPath { get; set; }

/// <inheritdoc cref="KNetCore{T}.ApplicationDisableJMX" />
[Parameter(
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Disable JMX. Default is JMX enabled without security.")]
public bool? DisableJMX { get; set; }

protected override void OnBeforeCreateGlobalInstance()
{
KNetPSHelper<KNetPSCore>.SetScalaVersion(ScalaVersion);
KNetPSHelper<KNetPSCore>.SetJarRootPath(KafkaJarLocation);
KNetPSHelper<KNetPSCore>.SetLog4JPath(Log4JPath);
KNetPSHelper<KNetPSCore>.SetLogPath(LogPath);
KNetPSHelper<KNetPSCore>.SetDisableJMX(DisableJMX);
}
}
}
2 changes: 2 additions & 0 deletions src/net/KNetPS/KNetPSHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public static class KNetPSHelper<TClass> where TClass : KNetCore<TClass>
public static void SetLogPath(string logPath) { JNetPSHelper<TClass>.Set(typeof(KNetCore<>), nameof(KNetPSCore.ApplicationLogPath), logPath); }

public static void SetScalaVersion(string scalaVersion) { JNetPSHelper<TClass>.Set(typeof(KNetCore<>), nameof(KNetPSCore.ApplicationScalaVersion), scalaVersion); }

public static void SetDisableJMX(bool? disableJMX) { JNetPSHelper<TClass>.Set(typeof(KNetCore<>), nameof(KNetPSCore.ApplicationDisableJMX), disableJMX); }
}
}

0 comments on commit eb9cd9b

Please sign in to comment.