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

Add possibility to create EventHub namespace with kafka #711

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public interface EventHubNamespace extends
*/
@Beta(Beta.SinceVersion.V1_7_0)
boolean isAutoScaleEnabled();
/**
* @return true if kafka enabled for the namespace, false otherwise
*/
@Beta(Beta.SinceVersion.V1_7_0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be 1.22 ?

boolean isKafkaEnabled();
/**
* @return current throughput units set for the namespace
*/
Expand Down Expand Up @@ -138,6 +143,19 @@ interface WithSku {
WithCreate withSku(EventHubNamespaceSkuType namespaceSku);
}

/**
* The stage of the event hub namespace definition enabling kafka.
*/
@Beta(Beta.SinceVersion.V1_7_0)
interface WithKafka {
/**
* Enables kafka.
*
* @return next stage of the event hub namespace definition
*/
WithCreate withKafka();
}

/**
* The stage of the event hub namespace definition allowing to add new event hub in the namespace.
*/
Expand Down Expand Up @@ -247,7 +265,8 @@ interface WithCreate extends
EventHubNamespace.DefinitionStages.WithSku,
EventHubNamespace.DefinitionStages.WithEventHub,
EventHubNamespace.DefinitionStages.WithAuthorizationRule,
EventHubNamespace.DefinitionStages.WithThroughputConfiguration {
EventHubNamespace.DefinitionStages.WithThroughputConfiguration,
EventHubNamespace.DefinitionStages.WithKafka {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public class EHNamespaceInner extends Resource {
@JsonProperty(value = "sku")
private Sku sku;

/**
* Properties of kafka resource.
*/
@JsonProperty(value = "kafkaEnabled")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thamer-ea
did you hand edit this file to add the property to the inner?

private boolean kafkaEnabled;

/**
* Provisioning state of the Namespace.
*/
Expand Down Expand Up @@ -175,4 +181,23 @@ public EHNamespaceInner withMaximumThroughputUnits(Integer maximumThroughputUnit
return this;
}

/**
* Get the kafkaEnabled value.
*
* @return the kafkaEnabled value
*/
public boolean kafkaEnabled() {
return this.kafkaEnabled;
}

/**
* Set the kafkaEnabled value.
*
* @param kafkaEnabled the kafkaEnabled value to set
* @return the EHNamespaceInner object itself.
*/
public EHNamespaceInner withKafkaEnabled(boolean kafkaEnabled) {
this.kafkaEnabled = kafkaEnabled;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ public boolean isAutoScaleEnabled() {
return Utils.toPrimitiveBoolean(this.inner().isAutoInflateEnabled());
}

@Override
public boolean isKafkaEnabled() {
return this.inner().kafkaEnabled();
}

@Override
public EventHubNamespaceImpl withKafka() {
this.inner().withKafkaEnabled(true);
return this;
}

@Override
public int currentThroughputUnits() {
return Utils.toPrimitiveInt(this.inner().sku().capacity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,45 @@ public void canManageEventHubNamespaceEventHubs() throws Exception {
}

@Test
public void canManageEventHubNamespaceAuthorizationRules() throws Exception {
public void canManageEventHubNamespaceWithKafka() throws Exception {
RG_NAME = generateRandomResourceName("javacsmrg", 15);
final String namespaceName = SdkContext.randomResourceName("ns", 14);

EventHubNamespace namespace = eventHubManager.namespaces()
.define(namespaceName)
.withRegion(REGION)
.withNewResourceGroup(RG_NAME)
.withNewManageRule("mngRule1")
.withNewSendRule("sndRule1")
.withKafka()
.create();

Assert.assertNotNull(namespace);
Assert.assertNotNull(namespace.inner());
Assert.assertTrue(namespace.isKafkaEnabled());

EventHubNamespace namespace2 = eventHubManager.namespaces()
.define(namespaceName)
.withRegion(REGION)
.withNewResourceGroup(RG_NAME)
.create();

Assert.assertNotNull(namespace);
Assert.assertNotNull(namespace.inner());
Assert.assertFalse(namespace.isKafkaEnabled());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thamer-ea
As of now the tests are failing with this assertion... Kafka Enabled seems to be false

}

@Test
public void canManageEventHubNamespaceAuthorizationRules() throws Exception {
RG_NAME = generateRandomResourceName("javacsmrg", 15);
final String namespaceName = SdkContext.randomResourceName("ns", 14);

EventHubNamespace namespace = eventHubManager.namespaces()
.define(namespaceName)
.withRegion(REGION)
.withNewResourceGroup(RG_NAME)
.withNewManageRule("mngRule1")
.withNewSendRule("sndRule1")
.create();

Assert.assertNotNull(namespace);
Assert.assertNotNull(namespace.inner());

Expand All @@ -202,10 +229,10 @@ public void canManageEventHubNamespaceAuthorizationRules() throws Exception {

eventHubManager.namespaces()
.authorizationRules()
.define("sndRule2")
.withExistingNamespaceId(namespace.id())
.withSendAccess()
.create();
.define("sndRule2")
.withExistingNamespaceId(namespace.id())
.withSendAccess()
.create();

rules = namespace.listAuthorizationRules();
set.clear();
Expand Down
Loading