Skip to content

Commit

Permalink
Created separate resource for Muting/Unmuting/ Getting mute status, R…
Browse files Browse the repository at this point in the history
…emoved obsolete resource
  • Loading branch information
dvayanu committed Oct 6, 2024
1 parent b813953 commit fd21f41
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.moskito.control.core;

import net.anotheria.util.TimeUnit;
import org.moskito.control.config.MoskitoControlConfiguration;
import org.moskito.control.core.status.MuteEventListener;
import org.moskito.control.core.status.StatusChangeEvent;
import org.moskito.control.core.status.StatusChangeListener;
Expand Down Expand Up @@ -72,6 +74,11 @@ public void mute(long delay) {
log.debug("Status change notifications muted for delay: " + getRemainingMutingTime());
}

public void mute() {
final long delay = TimeUnit.MINUTE.getMillis(MoskitoControlConfiguration.getConfiguration().getNotificationsMutingTime());
mute(delay);
}

/**
* Unmute if muted.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
public class MuteNotificationsAction extends BaseMoSKitoControlAction {
@Override
public ActionCommand execute(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) {
final long delay = TimeUnit.MINUTE.getMillis(MoskitoControlConfiguration.getConfiguration().getNotificationsMutingTime());
Repository.getInstance().getEventsDispatcher().mute(delay);
Repository.getInstance().getEventsDispatcher().mute();
return mapping.redirect();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.moskito.control.ui.restapi.control;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import net.anotheria.util.TimeUnit;
import org.moskito.control.core.MuteStatus;
import org.moskito.control.core.Repository;
import org.moskito.control.ui.restapi.ReplyObject;

@Path("notificationSettings")
@Produces(MediaType.APPLICATION_JSON)
@Server(url = "/api/v2")
@Tag(name = "Notification Settings API", description = "API for notification settings")
public class NotificationSettingsResource {
@Operation(summary = "Returns mute status",
description = "Returns whether the system is muted currently and for how long"
)
@ApiResponse(description = "Current mute status",
content = @Content(schema = @Schema(implementation = MuteStatus.class)))
@GET
@Path("status")
public ReplyObject getMuteStatus(){
return new ReplyObject("muteStatus", Repository.getInstance().getEventsDispatcher().getMuteStatus());
}

@Operation(summary = "Mutes the system",
description = "Mutes all notifications for the provided number of minutes, or default if not provided. Used for planed maintenance windows"
)
@ApiResponse(description = "Current mute status",
content = @Content(schema = @Schema(implementation = MuteStatus.class)))
@POST @Path("mute")
public ReplyObject mute(@QueryParam("minutes") Integer minutes){
if (minutes==null)
Repository.getInstance().getEventsDispatcher().mute();
else
Repository.getInstance().getEventsDispatcher().mute(TimeUnit.MINUTE.getMillis(minutes));
return new ReplyObject("muteStatus", Repository.getInstance().getEventsDispatcher().getMuteStatus());
}

@Operation(summary = "Unmutes the system",
description = "Cancels previously set mute status. This is useful if you muted for a maintenace window and want to unmute after it is over"
)
@ApiResponse(description = "Current mute status",
content = @Content(schema = @Schema(implementation = MuteStatus.class)))
@POST @Path("unmute")
public ReplyObject unmute(){
Repository.getInstance().getEventsDispatcher().unmute();
return new ReplyObject("muteStatus", Repository.getInstance().getEventsDispatcher().getMuteStatus());
}
}

0 comments on commit fd21f41

Please sign in to comment.