Skip to content

Instantly share code, notes, and snippets.

View sumanentc's full-sized avatar
🧑‍💻
Working from home

Suman Das sumanentc

🧑‍💻
Working from home
View GitHub Profile
Property Name Default Meaning
spark.dynamicAllocation.enabled FALSE Whether to use dynamic resource allocation, which scales the number of executors registered with this application up and down based on the workload
spark.dynamicAllocation.executorIdleTimeout 60s If dynamic allocation is enabled and an executor has been idle for more than this duration, the executor will be removed
spark.dynamicAllocation.initialExecutors minExecutors Initial number of executors to run if dynamic allocation is enabled.Ê
spark.dynamicAllocation.minExecutors 0 Lower bound for the number of executors if dynamic allocation is enabled.
spark.dynamicAllocation.schedulerBacklogTimeout 1s If dynamic allocation is enabled and there have been pending tasks backlogged for more than this duration, new executors will be requested.
spark.dynamicAllocation.sustainedSchedulerBacklogTimeout schedulerBacklogTimeout Same asÊspark.dynamicAllocation.schedulerBacklogTimeout, but used only for subsequent executor requests
package main
import (
"github.com/labstack/echo"
)
//main function
func main() {
// create a new echo instance
e := echo.New()
//GET API which return the name of the cats specified in QueryParam
//http://localhost:8000/cats?name=arnold&type=fluffy
func GetCats(c echo.Context) error {
catName := c.QueryParam("name")
catType := c.QueryParam("type")
return c.String(http.StatusOK, fmt.Sprintf("your cat name is : %s\nand cat type is : %s\n", catName, catType))
}
//http://localhost:8000/cats/json?name=arnold&type=fluffy
//data path variable accepts value as json/string
func GetCats(c echo.Context) error {
catName := c.QueryParam("name")
catType := c.QueryParam("type")
dataType := c.Param("data")
if dataType == "string" {
return c.String(http.StatusOK, fmt.Sprintf("your cat name is : %s\nand cat type is : %s\n", catName, catType))
} else if dataType == "json" {
func AddCat(c echo.Context) error {
type Cat struct {
Name string `json:"name"`
Type string `json:"type"`
}
cat := Cat{}
defer c.Request().Body.Close()
err := json.NewDecoder(c.Request().Body).Decode(&cat)
if err != nil {
log.Fatalf("Failed reading the request body %s", err)
package main
import (
"github.com/labstack/echo"
"fmt"
"net/http"
)
func main() {
// create a new echo instance
e := echo.New()
//Custom Middleware
// ServerHeader middleware adds a custom header to the response.
func serverHeader(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Header().Set("Custom-Header", "blah!!!")
return next(c)
}
}
@Entity
@Table(name = "city")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "string")})
@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId")
public class City implements Serializable,TenantSupport {
private static final long serialVersionUID = -4551953276601557391L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Aspect
@Component
public class CityServiceAspect {
@Before("execution(* com.example.service.discriminator.CityService.*(..))&& target(cityService) ")
public void aroundExecution(JoinPoint pjp, CityService cityService) throws Throwable {
org.hibernate.Filter filter = cityService.entityManager.unwrap(Session.class).enableFilter("tenantFilter");
filter.setParameter("tenantId", TenantContext.getCurrentTenant());
filter.validate();
}
}
@Configuration
public class MyInterceptor {
@Autowired
private JpaProperties jpaProperties;
@Bean
public EmptyInterceptor hibernateInterceptor() {
return new EmptyInterceptor() {